[Tutor] Creating an Identifier or Object Name from a String?

Luke Paireepinart rabidpoobear at gmail.com
Sat Feb 10 22:28:21 CET 2007

Hazlett, Les wrote:
> Hi,
> I read the information at 
> http://mail.python.org/mailman/listinfo/tutor but am still not sure 
> how to properly send a question.  Will I get an email response without 
> joining the list?
You will get an e-mail response from me because I am using the reply-all 
feature which sends a copy to you and another to the list.  Other people 
who don't reply with this method will not have e-mails you can see. You 
should join the list.
> I thought when I read the 2002 thread with the subject (Creating an 
> Identifier or Object Name from a String?), that I had found a solution 
> to my problem.  But, I can't make the concept work for creating an 
> object identifier. 
> THIS WORKS   [snip]
>     class nsf(object):
>         # name = ''
>         def __init__(self, id):
>             self.name = id
>     # main
>     cmdstr = "Ireland = nsf('Ireland')"
>     eval(cmdstr)
 >>> exec('x = "hello"')
 >>> print x

you're using the wrong function.
This is still a Very Bad Idea (tm) and you can almost always accomplish 
this in a safer way.

More information about the Tutor mailing list