Query about doing fortran-esque repeat formatting
Jean-Michel Pichavant
jeanmichel at sequans.com
Mon Nov 9 07:31:00 EST 2009
Glenn Hutchings wrote:
> Rob Briggs <rdbriggs <at> mun.ca> writes:
>
>
>> Is there a way to do a repeat formatting command like in Fortran? Rather
>> that doing this:
>>
>> print "%s %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f" %
>> (parmName[i], tmp[i][1], tmp[i][2], tmp[i][4], tmp[i][6], tmp[i][7],
>> tmp[i][8], tmp[i][9])
>>
>
> There certainly is. You can use python's string concatenation
> and repeat operators:
>
> print "%s" + " %-5.3f" * 7 % <stuff>
>
> Glenn
>
>
data = tuple(parmName[i]) + tuple(tmp[i])
print "%s" + " %-5.3f" * len(tmp[i]) % data
That should do the trick.
JM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091109/dcfb1ec2/attachment-0001.html>
More information about the Python-list
mailing list