Re: locals() and dictionaries

2006-02-02 Thread Kent Johnson
JerryB wrote: > Rocco: > thanks for your response. The examples were just made up. I don't > normally use 'dict' and 'str'. > I know I can create a dictionary with the variables I want, etc. My > question is not how to solve the problem, or how to come up with a > work-around (I'm getting pretty go

Re: locals() and dictionaries

2006-02-01 Thread Alex Martelli
JerryB <[EMAIL PROTECTED]> wrote: ... > is it possible to access the individual members of a dictionary using % > locals() when creating a string? Not by using the built-in locals(); you'd have to override locals to mean someting different (not recommended). Alex -- http://mail.python.org/ma

Re: locals() and dictionaries

2006-02-01 Thread JerryB
Rocco: thanks for your response. The examples were just made up. I don't normally use 'dict' and 'str'. I know I can create a dictionary with the variables I want, etc. My question is not how to solve the problem, or how to come up with a work-around (I'm getting pretty good at this one :), so my q

Re: locals() and dictionaries

2006-02-01 Thread Rocco Moretti
JerryB wrote: > Hi, > I have a dictionary, a string, and I'm creating another string, like > this: > > dict = {} > dict[beatles] = "need" > str = "love" > > mystr = """All you %(dict[beatles])s is %(str)s""" % locals() > > Why do I get > keyerror: 'dict[one]'? > > Is there a way to reference th

locals() and dictionaries

2006-02-01 Thread JerryB
Hi, I have a dictionary, a string, and I'm creating another string, like this: dict = {} dict[beatles] = "need" str = "love" mystr = """All you %(dict[beatles])s is %(str)s""" % locals() Why do I get keyerror: 'dict[one]'? Is there a way to reference the elements in a dictionary with locals() o