Ian Bicking: the old part of his blog

More on python metaprogramming comment 000

I liked that! Pretty cool. What about?

def belongs_to_classmethod(cls, what):
print cls.__name__, " Belongs to ", what
class MetaActiveRecord(type):
def __new__(cls, name, bases, dictionary):

Record = super(MetaActiveRecord, cls).__new__(cls, name, bases, dictionary)

if dictionary.has_key('belongs_to'):
Record.belongs_to_classmethod = classmethod(belongs_to_classmethod) Record.belongs_to_classmethod(dictionary['belongs_to'])

System Message: WARNING/2 (<string>, line 13)

Definition list ends without a blank line; unexpected unindent.

return Record

class ActiveRecord(object):
__metaclass__ = MetaActiveRecord
class Person(ActiveRecord):

belongs_to = 'project_manager' def __init__(self):

System Message: ERROR/3 (<string>, line 22)

Unexpected indentation.
print "Person __init__"

a = Person()

prints: Person Belongs to project_manager Person __init__

Comment on Re: More on Python Metaprogramming
by Gordon Scott