Are decorators really that different from metaclasses...
Hallvard B Furuseth
h.b.furuseth at usit.uio.no
Mon Aug 30 12:33:46 EDT 2004
Paul Morrow wrote:
> >>> def baz():
> ... """docstring of baz"""
> ...
> >>> baz.__doc__
> 'docstring of baz'
> >>> baz.__dict__.keys()
> []
>
> Say what? Why didn't the Python system put baz's docstring into it's
> namespace (__dict__)? And where did it put it?
I'm fairly new to Python, but I think you are just using the wrong
interface to access the namespace. __dict__ isn't necessarily
something's namespace, even if it has a __dict__:
>>> class C(object): __slots__ = 'hide'
...
>>> class D(C): pass
...
>>> o = D()
>>> o.show, o.hide = 3, 5
>>> o.__dict__
{'show': 3}
OTOH,
>>> dir(o)
['__class__', '__delattr__', '__dict__', ... 'hide', 'show']
>>> getattr(o, 'hide')
5
>>> def foo(): """docstring"""
...
>>> dir(foo)
['__call__', '__class__', '__delattr__', '__dict__', '__doc__', ...]
>>> setattr(foo, '__doc__', "nope")
>>> help(foo)
Help on function foo in module __main__:
foo()
nope
--
Hallvard
More information about the Python-list
mailing list