String handling and the percent operator
Erik Max Francis
max at alcyone.com
Fri Jul 14 19:49:32 EDT 2006
Tom Plunket wrote:
> I know that the message didn't have enough formatters, that's why I
> asked. (Although I would have assumed that the generator would get
> automatically converted to a sequence that was consumable by the
> interpolation operator...)
That's because::
aFormatString % anObject
is a shortcut for::
aFormatString % (anObject,)
so things like::
print "Your birthday is on %s" % date
are allowed. So when the object is an iterator, it's just treated as a
single value in a 1-tuple, rather than iterated over to get its own tuple.
--
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
Sometimes a cigar is just a cigar.
-- Sigmund Freud
More information about the Python-list
mailing list