How does one view the source of function defined in the interpreter?

M

mattc

1) It appears that it is possible to view the source of a function
defined in the interpreter; however, I seem to be unable to do it.
Here is the code and resulting error.
print("hello world")
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
inspect.getsourcelines(f)
File "C:\Python30\lib\inspect.py", line 678, in getsourcelines
lines, lnum = findsource(object)
File "C:\Python30\lib\inspect.py", line 526, in findsource
raise IOError('could not get source code')
IOError: could not get source code

2) Also, is there a method to inspect f in the form "f.inspect" or
"f.getsource" or "f.dump"?

3) One last thing, is there any documentation for augmenting,
extending, or editing a function in the interpreter once it is
defined?

Yes, I'm new. Yes, I've spent the obligatory hours searching the web
and use groups. Yes, I'd love to code in Python. Please help. Thank
you.
 
T

Terry Reedy

mattc wrote:
Once the interpreter reads lines of code, then, as far as the
interpreter is concerned, they are gone.
3) One last thing, is there any documentation for augmenting,
extending, or editing a function in the interpreter once it is
defined?

Use IDLE, edit code in an edit window, then run.
I generally use the interpreter or IDLE shell window only for
single-line commands.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top