__doc__ in compiled script
Peter Otten
__peter__ at web.de
Fri Nov 3 03:31:16 EST 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[0].
Seems like I hid the magic constant in some voodoo code. There is an
advantage over co_consts[0], though: it balks when there is no docstring.
Peter
More information about the Python-list
mailing list