how can I interpret a file within the interactive interpreter

Peter Otten __peter__ at web.de
Tue Nov 13 11:05:12 EST 2007


Peter J. Bismuti wrote:

> I want to interpret a file (or whatever you call it) and then keep the 
> interactive interpreter alive so I can then continue to issue commands.  

That's what the -i option is for.

> How can this be done?  I saw online a -m flag but it does not seem to work. 

-m is used to load a module via python's import mechanism.

$ echo 'print "Hello from", __name__' > tmp.py

$ python -m tmp
Hello from __main__

$ python -i tmp.py
Hello from __main__
>>> 

You can combine both options:

$ python -i -m tmp
Hello from __main__
>>> 

Peter



More information about the Python-list mailing list