__doc__ in compiled script

Peter Otten __peter__ at web.de
Fri Nov 3 10:14:55 CET 2006


Gabriel Genellina wrote:

> I have a script starting with a docstring. After compiling it with
> compile(), is there any way I could get the docstring? __doc__ on the
> code object doesn't work.


The lazy coder's approach:

>>> compiler.parse("""
... 'the docstring'
... print 42
... """).doc
'the docstring'

Peter



More information about the Python-list mailing list