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

mattc mcerini at
Thu Jan 29 17:48:03 CET 2009

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.

>>> def f():
	print("hello world")

>>> f
<function f at 0x0131EF18>
>>> f()
hello world
>>> import inspect
>>> inspect
<module 'inspect' from 'C:\Python30\lib\'>
>>> inspect.getsourcelines(f)
Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
  File "C:\Python30\lib\", line 678, in getsourcelines
    lines, lnum = findsource(object)
  File "C:\Python30\lib\", 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

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

More information about the Python-list mailing list