__doc__ in compiled script
__peter__ at web.de
Fri Nov 3 09:31:16 CET 2006
Fredrik Lundh wrote:
> Gabriel Genellina wrote:
>>> >>> co.co_consts[list(co.co_names).index("__doc__")]
>>> 'This is a docstring'
>> Good! I'll buy this one :) thanks!
> however, there's no 1:1 mapping between names and constants; if you want
> code that works by accident, you might as well use co_consts.
Seems like I hid the magic constant in some voodoo code. There is an
advantage over co_consts, though: it balks when there is no docstring.
More information about the Python-list