Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:

> In <[EMAIL PROTECTED]>, gangesmaster
> wrote:
> 
> > just something i thought looked nice and wanted to share with the rest
> > of you:
> > 
> >>>> class x(object):
> > ...     def __metaclass__(name, bases, dict):
> > ...             print "hello"
> > ...             return type(name, bases, dict)
> > ...
> > hello
> >>>>
> > 
> > instead of defining a separate metaclass function/class, you can do
> > it inline. isn't that cool?
> 
> But why use a metaclass?  If the meta class is only applied to *one*
> class, can't you do at class level whatever the metaclass is doing!?

Most but not all of the "whatever".  E.g.:

class X:
    class __metaclass__(type):
        def __str__(cls): return 'The great class X!'

print X


You can't make "print X" behave arbitrarily w/o a custom metaclass.


Alex
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to