is there a better way to walk a file system?
Peter Otten
__peter__ at web.de
Fri Jul 1 13:02:23 EDT 2005
George Sakkis wrote:
> By the way, from this example I discovered that properties cannot be
> unbound, i.e. using path.ext instead of getExtension raises TypeError.
> Couldn't/shouldn't Class.prop(instance) be allowed as equivalent of
> instance.prop, just as methods ?
Use the property's __get__() method instead:
>>> class A(object):
... def __init__(self, value):
... self._value = value
... value = property(lambda self: self._value)
... def __repr__(self): return "A(%r)" % self._value
...
>>> a = A(42)
>>> A.value.__get__(a)
42
>>> sorted([A(42), A(2), A(4)], key=A.value.__get__)
[A(2), A(4), A(42)]
Peter
More information about the Python-list
mailing list