From: Edward P. <epo...@te...> - 2003-07-03 20:13:12
|
Hello, I am using Jython as a scripting language. To modify the python language for my audience, I have overridden things like __getitem__, __cmp__, __len__ etc. But no matter what I do, I can't override __getattr__. I have tried: adding a __getattr__ to my java class def. I also tried using code like this: def DataSeries__getattr__(self, name): return self.getWrapper(name); def bindFuncToClass(func, clas, methodName = None): method = new.instancemethod(func, None, clas) if not methodName: methodName = func.__name__ clas.__dict__[methodName] = method bindFuncToClass(DataSeries__getattr__, DataSeries, "__getattr__"); What is it with getattr that makes it an exception? The others work ok. I require this as some objects are created on the Java side and others in the python side, but the python scripts use both. Any workarounds for this? Thanks -Ed |
From: Oti <oh...@ya...> - 2003-07-03 20:53:06
|
[ Edward Povazan ] > I am using Jython as a scripting language. To modify the python > language for > my audience, I have overridden things like __getitem__, __cmp__, > __len__ > etc. > But no matter what I do, I can't override __getattr__. > > What is it with getattr that makes it an exception? The others work > ok. Special methods simply are not fully supported for Java objects (you might want to read the whole thread mentioned below to get a feeling of it). > Any workarounds for this? Here is one: http://aspn.activestate.com/ASPN/Mail/Message/1415861 Best wishes, Oti. __________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com |
From: Michel P. <mi...@di...> - 2003-07-05 21:14:22
|
On Thursday 03 July 2003 15:51, Oti wrote: > Special methods simply are not fully supported for Java objects (you > might want to read the whole thread mentioned below to get a feeling of > it). > > > Any workarounds for this? > > Here is one: > http://aspn.activestate.com/ASPN/Mail/Message/1415861 This patch makes plenty of sense to me. If I remember correctly CPython = with=20 Extension classes used to have a similar problem; some magic was needed t= o=20 override setattr and getattr in C so that ZODB could work efficiently. =20 Zope-driven improvements fixed the problem. Perhaps __setattr__ and __getattr__ could be formalized into an Atributab= le=20 interface. But that may not be necessary. -Michel |