Bug in % string formatting?

Fernando Pérez fperez528 at yahoo.com
Wed Dec 19 15:12:25 CET 2001


If this is not a bug in % string formatting, I'd love to understand what is 
going on.

The example code is:

names = {'John' : ('John Doe','jodoe at nowhere'),
         'Jane' : ('Jane Doe','jadoe at nowhere'),
         }

format_string = '%s <%s>\n%s <%s>'

format_list = names['John'][:] + names['Jane'][:]

# This works ok
print 'With prebuilt list:'
print format_string % format_list

# but this fails. The format string is copied verbatim from above
print 'Explicit list construction:'
print format_string % names['John'][:] + names['Jane'][:]


Upon executing this, the output is:

$ python test.py
With prebuilt list:
John Doe <jodoe at nowhere>
Jane Doe <jadoe at nowhere>
Explicit list construction:
Traceback (most recent call last):
  File "test.py", line 15, in ?
    print format_string % names['John'][:] + names['Jane'][:]
TypeError: not enough arguments for format string

This is all under Python 2.1.1, Mandrake 8.0.

Any insight would be greatly appreciated.

Regards,

Fernando.



More information about the Python-list mailing list