One more great thing I learnt - Thank a lot, will try that soon. class declaration any where, wow ....
:-) On Wed, Apr 13, 2011 at 7:46 AM, Dirley <[email protected]> wrote: > You can dynamically subclass without eval. Like that: > > class A(object): > __storm_table__ = 'a' > def make_subclass(base, storm_table): > class DynamicallyGeneratedSubclass(base): > __storm_table__ = storm_table > return DynamicallyGeneratedSubclass > C = make_subclass(A, 'c') > issubclass(C, A) # True > C.__storm_table__ # 'c' > 2011/4/12 Steve Kieu <[email protected]> >> >> Hi, >> >> Thanks for replying, I have thought about subclassing but how to do it >> dynamically. The only one way I can think of is dynamically generate >> python string contains the class definitions and then eval it to >> return the class object. >> >> Where is my python doc for eval-ing string :-) >> >> Any other way better than this? >> >> Cheers, >> >> >> >> >> On Wed, Apr 13, 2011 at 6:48 AM, Gustavo Niemeyer >> <[email protected]> wrote: >> >> I have tried to use setattr(AccessLog, '__storm_table__', >> >> 'table-name') which get rid of the error. However I can only set it >> >> once. Reset it to another value will not work, it still pointing to >> >> the old one. >> > >> > Yes, as you have figured the attribute is cached for performance, so >> > that kind of trick won't work indeed. >> > >> > What you can do, though, is have multiple subclasses and define custom >> > tables for them. >> > >> > -- >> > Gustavo Niemeyer >> > http://niemeyer.net >> > http://niemeyer.net/blog >> > http://niemeyer.net/twitter >> > >> >> >> >> -- >> Steve Kieu >> >> -- >> storm mailing list >> [email protected] >> Modify settings or unsubscribe at: >> https://lists.ubuntu.com/mailman/listinfo/storm > > -- Steve Kieu -- storm mailing list [email protected] Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/storm
