FAQ
Just a quick question. Consider this:

dict01 = { '1': 'a', '2': 'b' }

for c in range(1, 3):
print "%(c)s" % locals(), "%(1)s" % dict01

Returns:

1 a
2 a

But, using this loop instead:

for c in range(1, 3):
print "%(c)s %(1)s" % (locals(), dict01)

Results in an error: TypeError: format requires a mapping

Why doesn't the second loop work? It seems to be a cleaner way of
doing this. Am I missing something?

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 4 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedAug 20, '03 at 5:33p
activeAug 20, '03 at 10:45p
posts4
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase