Source inspector
The .pythonrc.py is the script that executes when interactive interpreter starts up. You need to unsure that an environment variable PYTHONSTARTUP contains the path to that file.
export PYTHONSTARTUP=/home/partecs/.pythonrc.py
Here is a handy code snippet that one could add into your .pythonrc.py file.
import pydoc import inspect import rlcompleter, readline readline.parse_and_bind('tab: complete') def source(obj): """source of the obj.""" try: pydoc.pipepager(inspect.getsource(obj), 'less') except IOError: pass
Now for the fun part, run the Python interpreter and hit the tab button twice. You have the tab complete feature. Also try out the following statements.
>>> import os >>> source(os)
You should be able to view the source of the os module.
You can also use your pythonrc.py file in Zope’s debug mode. To start up Zope’s debug mode run the following statement.
./zope/instancehome/bin/zopectl debug
On the interpreter run the following statement.
>>> execfile('/path/to/.pythonrc.py')
If you don’t like running execfile everytime you run Zope in the debug mode you could simply edit and modify
lib/python/Zope2/Startup/zopectl.py and replace the line
"import Zope2; app=Zope2.app())" with
"import Zope2; app=Zope2.app(); execfile('/home/partecs/.pythonrc.py')".
Great tip; I should have known that earlier.
The same can be done with the pdb.
Instead of execfile(‘/home/partecs/.pythonrc.py’) you can add ‘import user’. That’s the standard python way to load that file; it is slightly more robust and more flexible. I vote for putting that into standard Zope.
More info on my blog; click on my name in the comment header.
October 17th, 2006 | #
ipython, interactive python, has this functionality built-in:
>>> import os
>>> os??
March 22nd, 2007 | #