Sanjay wrote: >>Can you flesh out your use case a little bit and tell why you can't solve >>the problem with inheritance or a meta class? > > > I have to study about metaclass and see whether this can be handled. It > seemed inheritence is not working. > > PROBLEM: Separating plumbing code and business logic while using > SQLAlchemy ORM. > (snip) > DB definitions and plumbing code goes into one module, say db.py: > > import sqlalchemy.mods.threadlocal > from sqlalchemy import * > > global_connect('postgres://userid:[EMAIL PROTECTED]:5432/tm') > person_tbl = Table('person', default_metadata, autoload = True) > class Person(object): > pass (snip)
> Business logic in another module, say bo.py > > Class PersonBO(Person): > def Block(): > blocked = True <OT> shouldn't it be: class PersonBO(Person): def block(self): self.blocked = True </OT> > While using PersonBO in another module, like this: > > p1 = PersonBO(passport = "[EMAIL PROTECTED]", first_name='john', > last_name='smith', email = "[EMAIL PROTECTED]") > p2 = PersonBO(passport = "[EMAIL PROTECTED]", first_name='ed', > last_name='helms', email = "[EMAIL PROTECTED]") > p3 = PersonBO(passport = "[EMAIL PROTECTED]", first_name='jonathan', > last_name='lacour', email = "[EMAIL PROTECTED]") > > # add a contact > p1.contacts.append(Contact(person=p2)) > > the following error message occurs: > > AttributeError: 'PersonBO' object has no attribute 'contacts' Strange. > What I guess, from my limited knowledge of the technologies involved, > is that assign_mapper does some magic only on Person class, and things > work. But after inheritence, it is not working. Anyway, there are other ways to reuse implementation, like composition/delegation. You may want to have a look at __getattr__/__setattr__ magic methods. > As far as my project is concerned, I have found out some other way of > doing the things, Care to explain your solution ? -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list