Thanks all, I think I'l stick with the '*' method because this is just a one time thing for a __repr__ function and it seems easiest.<br><br><div class="gmail_quote">On Sun, May 31, 2009 at 6:32 AM, Terry Reedy <span dir="ltr"><<a href="mailto:tjreedy@udel.edu">tjreedy@udel.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div></div><div class="h5">Gary Herron wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Cameron Pulsford wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello all, I'm trying to pretty print a list, so I am doing something like<br>
<br>
print '%3d' % integer<br>
<br>
only I would like that 3 to be a variable, instead of hardcoded. Is this possible, or are there any other ways to accomplish this? Thanks!<br>
</blockquote>
<br>
Use a '*' instead of fixed width, and then supply the actual width as a separate parameter:<br>
<br>
 >>> print '%*d' % (5,123)<br>
 123<br>
</blockquote>
<br></div></div>
In the new string formating, fields can be nested withing fields.  For 3.1, with auto field numbering:<br>
>>> "{:{}d}".format(12,4)<br>
'  12'<br>
<br>
Otherwise, {0:{1}d}<br>
<br>
tjr<div><div></div><div class="h5"><br>
<br>
-- <br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</div></div></blockquote></div><br>