Starting a script interactively?

James Kew james.kew at btinternet.com
Sat Jan 3 07:45:31 EST 2004


"Al Kabaila" <a_kabaila at yahoo.com.au> wrote:
> David Klaffenbach wrote:
> > Is there a way from within a python script to cause the interpreter to
> > be in interactive mode after the script finishes?
>
> In Linux OS, add first line in myscript.py as follows:
> #! /<path to the directory where python lives>/python
> and make sure that myscript.py is executable.  I don't know if this works
> under dos, but there should be some equivalent.

There is, for NT-class systems -- add .py to PATHEXT -- but I think the
Python installer does this automatically. (The ActiveState installer
certainly does.)

But that only answers the question "how do I make a script executable". The
OP wants to know how to have a script drop to the Python interpreter, rather
than back to the shell, when the script completes.

Under Windows, you could achieve this behaviour for _all_ Python scripts by
tweaking the "open" action of the .py file association to add the -i flag.
But I think the OP wants to do it only for _some_ scripts, and from _within_
the script -- nothing comes to mind for this.

James





More information about the Python-list mailing list