Python: truncate and pad using format specification mini language
<p>I'm currently writing code which pads a string with spaces, using Python's <a href="http://docs.python.org/2/library/string.html#formatspec" rel="nofollow">format specification mini language</a>:</p>

<pre><code>print('''{user:&lt;10}, you're wellcome!'''.format(user='John Doe'))
</code></pre>

<p>The output is:</p>

<pre><code>John Doe  , you're wellcome!
</code></pre>

<p>However, if user is something like 'Joooooooooooohn Doe', I'd like it to behave like:</p>

<pre><code>Jooooooooo, you're wellcome!
</code></pre>

<p>Is there a way to perform truncation AND padding using the format specification mini language?</p>

<p>Thanks!</p>
