Per instance descriptors ?

Ziga Seilnacht ziga.seilnacht at gmail.com
Wed Mar 22 15:45:44 CET 2006


bruno at modulix wrote:
> Hi
>
> I'm currently playing with some (possibly weird...) code, and I'd have a
> use for per-instance descriptors, ie (dummy code):

<snip>

> Now the question: is there any obvious (or non-obvious) drawback with
> this approach ?

Staticmethods won't work anymore:

>>> class Test(object):
...     @staticmethod
...     def foo():
...         pass
...     def __getattribute__(self, name):
...         v = object.__getattribute__(self, name)
...         if hasattr(v, '__get__'):
...             return v.__get__(self, self.__class__)
...         return v
...
>>> test = Test()
>>> test.foo()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: foo() takes no arguments (1 given)


> TIA
> --
> bruno desthuilliers
> python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
> p in 'onurb at xiludom.gro'.split('@')])"

Ziga




More information about the Python-list mailing list