On 10/23/10 01:19, David Hutto wrote: > If I understand what i just said correctly, it just means it tells the > string what type to convert from when placing it into the final > result.
basically, when doing this %-interpolation, python does this: ("NEW LOW: %%.%sf at %%s" % i) % (lowz, timestamp) do the first interpolation: "NEW LOW: %%.%sf at %%s" % i it's to be noted that %% is replaced by a single %, and %s is replaced by the right argument of %, so if i == 5 it now becomes: "NEW LOW: %.5sf at %s" % (lowz, timestamp) and now do the second interpolation, lowz is formatted with %.5f which means a floating value (f) with 5 decimal place, and timestamp is inserted in place of %s; so if you have lowz = 81.345678901234 and timestamp = "last year": "NEW LOW: 81.34567 at last year" However, as Steven noted, the complex, 2-phase interpolation can be simplified using the '*' decimal place specifier: ("NEW LOW: %%.%sf at %%s" % i) % (lowz, timestamp) # is equivalent with: "NEW LOW: %.*f at %s" % (i, lowz, timestamp) and Steven also remarked that now the interpolation is so simple, there is very little benefit in separating it into a different function. _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor