dynamic creating of class

Erik Max Francis max at alcyone.com
Sun Jun 22 19:29:09 EDT 2003


Marek "Baczek" Baczyñski wrote:

> You're calling a string. What you really want is
> # the pythonic way
> kind = B # bind kind to object under the name B
> run = kind()
> or
> # the ugly way, sometimes the only though
> kind = 'B'
> run = eval(kind)()

If what you think you have is simply a name, it's far better to turn
that name into an object by lookup in a dictionary (e.g., globals())
rather than eval'ing it, just on the off-chance that you don't in fact
have a simple name after all.

-- 
   Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
 __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/  \ ... Not merely peace in our time, but peace for all time.
\__/  John F. Kennedy




More information about the Python-list mailing list