PEP318: property as decoration
frobozz_electric at hotmail.com
Thu Jun 12 05:47:55 CEST 2003
"Gerrit Holl" <gerrit at nl.linux.org> wrote in message
> Hmm, that doesn't seem to work. __doc__ is not in my local namespace yet.
Here`s a brittle hack to resolve that issue:
"""returns the calling function"""
# pull function name from outer scope (one)
fname = inspect.currentframe(1).f_code.co_name
# pull function itself from outer scope of one (two)
func = inspect.currentframe(2).f_locals[fname]
# func is a method, pull function from class dict
# This is BRITTLE! Cannot guarantee this methods'
# class is at outer scope of two (three). This requires
# a better lookup sequence.
cdict = inspect.currentframe(3).f_locals
return cdict.get(fname, None)
Then, inside your method you can do this:
"foo property's doc string"
def fset(self, value):
self._foo = value
return fget, fset, fdel, this().__doc__
As I say, "this" is a very brittle hack, so don't try this at home (pardon
More information about the Python-list