Create a new class on the fly

py_genetic conor.robinson at gmail.com
Wed May 30 20:44:06 EDT 2007


Is this possible or is there a better way.  I need to create a new
class during runtime to be used inside a function. The class
definition and body are dependant on unknows vars at time of exec,
thus my reasoning here.

class PosRecords(tables.IsDescription):


class A(object):
    self.__init__(self, args):
         ........
    def mkClass(self, args):
          eval( "class B(object): ...") #definition on B is dependant
on dynamic values in string
          ......do stuff with class


thanks.




More information about the Python-list mailing list