metaclasses

Michele Simionato mis6 at pitt.edu
Tue Jul 29 15:36:26 CEST 2003


Simon Burton <simonb at webone.com.au> wrote in message news:<pan.2003.07.28.22.25.25.311058 at webone.com.au>...
> It seems this is a more general way to build classes than inheritance.
> Is this a reasonable viewpoint?
> 
> >>> 
> >>> def meth1(self):
> ...   print "i am meth1"
> ... 
> >>> def meth2(self):
> ...   print "i am meth2"
> ... 
> >>> Foo = type("Foo",(),{'meth':meth1}) # make a class
> >>> foo = Foo() # make an instance
> >>> foo.meth() # call a method
>  i am meth1
> >>> 
> 
> Simon.

Yes, they are basically class factories. They interfer in the creation
of classes in a somewhat magical way, and are inherited. See

http://www-106.ibm.com/developerworks/library/l-pymeta.html

for more (there is also a second, more advanced paper which should
appear soon, we sent it more than a month ago!)

 

            Michele




More information about the Python-list mailing list