Re: __doc__ in compiled script

2006-11-03 Thread Peter Otten
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

Re: __doc__ in compiled script

2006-11-03 Thread Peter Otten
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

Re: __doc__ in compiled script

2006-11-02 Thread Fredrik Lundh
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]. -- http:

Re: __doc__ in compiled script

2006-11-02 Thread Gabriel Genellina
At Thursday 2/11/2006 17:54, Peter Otten 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. > I can't use __import__ because the script has top-level statements > that hav

Re: __doc__ in compiled script

2006-11-02 Thread Gabriel Genellina
At Thursday 2/11/2006 17:59, Fredrik Lundh 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. > > I can't use __import__ because the script has top-level statements that

Re: __doc__ in compiled script

2006-11-02 Thread Peter Otten
Gabriel Genellina wrote: > Hello > > 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. > I can't use __import__ because the script has top-level statements > that have to be execut

Re: __doc__ in compiled script

2006-11-02 Thread Fredrik Lundh
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. > > I can't use __import__ because the script has top-level statements that > have to be executed on

__doc__ in compiled script

2006-11-02 Thread Gabriel Genellina
Hello 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. I can't use __import__ because the script has top-level statements that have to be executed only once (it's not supposed to b