Referencing vars, methods and classes by name

Paul Rubin http
Thu Feb 8 03:32:12 EST 2007


"Sagari" <boyandin at gmail.com> writes:
> $a = 'b';
> $obj =& new $a(); // instantiating class b()

Classes are first class objects in python:

  class b:   .....  # define class b

We could assign the class object to a variable

  a = b

and make an instance:

  obj = a()    # same as "obj = b()"

Continuing that example we could make a dispatch table of classes:

   class b: ...
   class c: ...
   class d: ...

   table = [b, c, d]    # 3 element array, each element is a class

   i = 1
   a = table[i]         # this means a = c

   obj = a()            # instantiate c



More information about the Python-list mailing list