why does the % string format operator only take tuples?
Steve Holden
sholden at holdenweb.com
Wed Apr 4 11:25:23 EDT 2001
"Clarence Gardner" <clarence at netlojix.com> wrote in message
news:986344880.1233352496 at news.silcom.com...
> On Tue, 03 Apr 2001, Ram Bhamidipaty wrote:
> >
> >
> >Does anyone else think it would be a good idea of the % operator
> >were extended to also handle lists?
> >
> >-Ram
>
> You want as few types as possible to be treated as containers for the
> data to be formatted, because you have a problem formatting an object
> of those types.
>
> For example, if you want to print the tuple (1,2), you can't use
> print '%s' % (1,2)
> Instead, you have to do something like
> print '%s' % `(1,2)`
> Making % treat lists as tuples would just mean there were more objects
> that can't be formatted.
>
Or, perhaps,
print '%s' % ((1, 2), )
which uses a tuple containing a single tuple.
regards
Steve
More information about the Python-list
mailing list