Display of Python Source
Stefan Franke
spamfranke at bigfoot.de
Wed May 12 12:09:25 EDT 1999
On Wed, 12 May 1999 06:34:57 -0700, "Emile van Sebille" <emile at fenx.com> wrote:
>Is there a way to recall and display the python source code from the shell?
[...]
>Now I'd like to load/examine/modify the code segment.
Hardly, since the "code segment" is byte compiled. It can be disassembled with
the "dis" module (see below), but there is no way to get the source code
(including variable names and comments), even though the translation process is
pretty straightforward.
The best way for your kind of interactive work is propably to choose an IDE,
which allows you to execute arbitrary regions of an editor window. The Emacs
pymode does, IDLE propably also.
Stefan
>>> def f():
... print "Hello"
>>> import dis
>>> dis.dis(f)
0 SET_LINENO 1
3 SET_LINENO 2
6 LOAD_CONST 1 ('Hello')
9 PRINT_ITEM
10 PRINT_NEWLINE
11 LOAD_CONST 0 (None)
14 RETURN_VALUE
More information about the Python-list
mailing list