Best way to create a class dynamically on the fly?
Robert Oschler
Oschler at earthlink.net
Sat Sep 28 22:08:49 EDT 2002
"Evan" <evan at 4-am.com> wrote in message news:3D96511D.2040407 at 4-am.com...
> Robert Oschler wrote:
> > What is the best way to create a Python class dynamically at runtime?
>
> ALL Python classes are created dynamically at runtime. The following is
> not a declaration in the sense that you're accustomed to from C/C++, it
> is normal code executed when the containing file is run (or imported):
>
> class Foo:
> def meth1(self):
> return "I am a method"
>
<snip>
Evan,
I understand but what I'm after is building the class itself dynamically,
akin to the way you can manufacture a prolog predicate on the fly. For
example, if wanted to create a class whose name was provided in a string
variable called ClassName, at runtime. Or did I misunderstand your reply?
thx
More information about the Python-list
mailing list