Monday, May 12, 2008

Linking Python startup.py and .pythonrc.py

On interactive startup, Python reads either $PYTHONSTARTUP or ~/pylib/startup.py, if it exists. On noninteractive startup, Python reads ~/.pythonrc.py, if it exists.

python without options counts as interactive and python -i counts as noninteractive. So

python

reads startup.py while

python -i foo.py

reads .pythonrc.py.

If it matters that the same modules preload on both interactive and noninteractive startup, ~/pylib/startup.py and ~/.pythonrc.py might help. The command is

ln ~/pylib/startup.py ~/.pythonrc.py

and it's important that ~/.pythonrc.py doesn't at first exist.

No comments: