load a class dynamically

Jeremy Lowery jslowery at hotmail.com
Fri Nov 30 21:48:58 EST 2001


I know that implementing this may be a little bit of work, but could someone
point me in the right direction?

Have a text file that only contains a class definition, or just a string for
the sake of simplicity.

str = "class myClass:\n\tdef __init__(self):\n\t\tself.v = 1"

#the magical code goes here.

obj = myClass()
# of course, it doesn't have to be called like that, but to
#get the ability to instantainate that class.

Jeremy






More information about the Python-list mailing list