switch recipe?
Mark McEahern
mark at mceahern.com
Fri Jul 12 16:25:40 EDT 2002
> the template variable ......
Good point, that certainly could have been explained better. For what it's
worth, in the original post in the other thread, I provided a list of the
features that were used so that anyone who wanted to investigate could do a
little searching to learn more. I could have spent more time compiling that
list. Thanks for the feedback.
> I always seem to have a semi violent reaction when I see locals().
Hmm, this may sound naive, but I don't understand why. Consider these
admittedly cobbled examples:
def colorize1(value, color):
template = "<%(color)s>%(value)s</%(color)s>"
return template % locals()
def colorize2(value, color):
template = "<%(color)s>%(value)s</%(color)s>"
return template % {'color': color, 'value': value}
def colorize3(value, color):
template = "<%s>%s</%s>"
return template % (color, value, color)
That's the precise order in which I'd rank them. <wink>
What could possibly be wrong with the use of locals() in colorize1()?
Cheers,
// mark
-
More information about the Python-list
mailing list