naming objects from string

Wildemar Wildenburger wildemar at freakmail.de
Thu Sep 21 00:59:05 EDT 2006


manstey wrote:
> Hi,
> 
> But this doesn't work if I do:
> 
> a=object()
> x='bob'
>  locals()[x] = a
> 
> How can I do this?

You can. I just copy/pasted your code and it works fine here. (You are 
aware that there is whitespace before locals() that you have to remove 
before you feed it to the snake?)

What error did you get?

Let me again stress that using locals and globals is a bit contrived, 
whereas the dictionary approach from my other post is not.


Just out of curiosity: Why do you want to do this anyway?

wildemar



More information about the Python-list mailing list