PYTHONSTARTUP ignored by python -i file.py?

David M. Cooke cookedm at physics.mcmaster.ca
Wed Sep 13 16:59:33 EDT 2000


At some point, hzhu at users.sourceforge.net (Huaiyu Zhu) wrote:

> Here's a simple thing that has bugged me for a while.
> 
> I want to do something like
> 
> python -i file.py
> 
> and get the effect of 
> 
> python
> >>> from file import *
> 
> However, it appears the .pythonrc in my $PYTHONSTARTUP is not read (which
> does the readline, command completion and history recall stuff).

from the man page:

       -i     When a script is passed as first argument or the -c
              option is used, enter interactive mode  after  exe­
              cuting the script or the command.  It does not read
              the $PYTHONSTARTUP file.  This  can  be  useful  to
              inspect  global  variables  or a stack trace when a
              script raises an exception.

> How do I achieve both results (.pythonrc and file.py) with one command line?

You could try this:

python -i -c "execfile('$PYTHONSTARTUP'); from file import *"

but then it's probably easier to type
python
>>> from file import *

-- 
|>|\/|<
----------------------------------------------------------------------------
David M. Cooke
cookedm at mcmaster.ca



More information about the Python-list mailing list