Stuff spaces at end of lines in file
<p>I am trying to read a fixed with file that has lines/records of different lengths. I need to stuff spaces at the end of the lines which are less than the standard length specified.</p>

<p>Any help appreciated.</p>

<p><a href="http://i.stack.imgur.com/N5Kbd.png" rel="nofollow">enter image description here</a></p>

<p>You can use <a href="https://docs.python.org/3.3/library/string.html" rel="nofollow">string.format</a> to pad a string to a specific length.</p>

<p>The documentation says that <code>&lt;</code> pads to the right so to pad a string with spaces to the right to a specific length you can do something like this:</p>

<pre><code>&gt;&gt;&gt; "{:&lt;30}".format("foo")
'foo                           '
</code></pre>

python fixed-width