Are decorators really that different from metaclasses...
Hallvard B Furuseth
h.b.furuseth at usit.uio.no
Mon Aug 30 18:33:46 CEST 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
['__class__', '__delattr__', '__dict__', ... 'hide', 'show']
>>> getattr(o, 'hide')
>>> def foo(): """docstring"""
['__call__', '__class__', '__delattr__', '__dict__', '__doc__', ...]
>>> setattr(foo, '__doc__', "nope")
Help on function foo in module __main__:
More information about the Python-list