Play with classes

Terry Reedy tjreedy at udel.edu
Thu Feb 26 10:23:15 EST 2004


"Zunbeltz Izaola" <zunbeltz at wm.lc.ehu.es.XXX> wrote in message
news:cth4qte878u.fsf at lcpxdf.wm.lc.ehu.es...
> Hi to all!
>
> I wonder if it possible (i'm sure python can do :-) ) to define classes
on
> runtime. My problem (schematically) is the folowwin.

The class statement, like all statements except the global directive, it a
runtime executable statement.  So, in a sense, all class objects are
defined (created) at runtime.  So you are perhaps asking, "Can I write a
class statement at runtime (using user input)?"  If so, yes.  Create a
string with the code you want executed, then exec it with an exec
statement.  Or you can use the approach others suggested of interpreting
user input to build up a class object.  Your choice.

Terry J. Reedy







More information about the Python-list mailing list