inline metaclasses
K.S.Sreeram
sreeram at tachyontech.net
Mon Jul 3 23:17:26 EDT 2006
Marc 'BlackJack' Rintsch wrote:
> 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!?
The very fact that you can put a loop inside __metaclass__ may be reason
enough for a one-off metaclass.
Here's a contrived example:
class X :
def __metaclass__( name, bases, dict ) :
for k,v in dict.items() :
if k.startswith('get_') :
dict[ k[4:].upper() ] = property( v )
return type( name, bases, dict )
def get_a( self ) :
...
def get_b( self ) :
...
o = X()
print o.A
print o.B
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 260 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20060704/1ecd7993/attachment.sig>
More information about the Python-list
mailing list