float formatting
Diez B. Roggisch
deets at nospam.web.de
Wed Jan 25 14:50:19 EST 2006
> However, if I do that I get errors saying that all args were not
> converted during string formatting. An escaped 'i' does not work
> either.
You need to format the string twice - first, to generate the float
formatting string, and then to format the string.
Like this:
num = 7.12345678901234567
for i in xrange(3,7):
print ("%%.%if" % i) % num
Note the %% that produces a single % for the second string interpolation.
Diez
More information about the Python-list
mailing list