Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #13317
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <arnodel@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.017 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'constructor': 0.07; 'subject:code': 0.07; 'subject:object': 0.07; 'assert': 0.09; 'stored': 0.13; 'def': 0.15; 'subject:function': 0.16; 'received:209.85.213.46': 0.23; 'received:mail- yw0-f46.google.com': 0.23; 'function': 0.27; 'all,': 0.28; 'pass': 0.29; 'constant': 0.29; 'message-id:@mail.gmail.com': 0.29; 'subject:?': 0.31; 'actually': 0.33; "can't": 0.33; 'to:addr :python-list': 0.33; 'wondering': 0.33; 'subject:How': 0.35; 'but': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'subject:its': 0.84; 'subject:know': 0.93 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; bh=Uowi19c7Ycu8Fv46TEcOA0W5NaBLuD+PPqfJmvtgOhA=; b=Y7c6iy/BBPIUiAY5wE4jRv4quYyayz7kvLEkjYidZcFzM4r/MVRX4LlRgCEMxY3e+u /dUd4j/OK1Oyfuko/mujNbl4QoxtLgLWG2EEyqfr3dx+rJZQHW7WnGR1UibsUTVM4sUb OuQRdCZgt7PcnLzvIitaOXqlTz7D/SX7jEhpE= |
| MIME-Version | 1.0 |
| Date | Thu, 15 Sep 2011 12:10:58 +0100 |
| Subject | How does a function know the docstring of its code object? |
| From | Arnaud Delobelle <arnodel@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1161.1316085061.27778.python-list@python.org> (permalink) |
| Lines | 22 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1316085061 news.xs4all.nl 2477 [2001:888:2000:d::a6]:49429 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:13317 |
Show key headers only | View raw
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