Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #13317
| Date | 2011-09-15 12:10 +0100 |
|---|---|
| Subject | How does a function know the docstring of its code object? |
| From | Arnaud Delobelle <arnodel@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1161.1316085061.27778.python-list@python.org> (permalink) |
Hi all,
You can do:
def foo():
"foodoc"
pass
function = type(lambda:0)
foo2 = function(foo.__code__, globals())
assert foo2.__doc__ == "foodoc"
I am wondering how the function constructor knows that foo.__code__
has a docstring. I can see that
foo.__code__.co_consts == ('foodoc',)
But I can't find where in foo.__code__ is stored the information that
the first constant in foo.__code__ is actually a docstring.
--
Arnaud
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
How does a function know the docstring of its code object? Arnaud Delobelle <arnodel@gmail.com> - 2011-09-15 12:10 +0100
csiph-web