Forcing interactive interpreter without (-i)

M

Miki Tebeka

Hello All,

If there a way a script can tell Python to enter interactive mode even if
the -i command line switch was not given?

I want py2exe to create an interactive session, without writing my own
REPL.

Thanks.
 
T

Thomas Heller

Miki Tebeka said:
Hello All,

If there a way a script can tell Python to enter interactive mode even if
the -i command line switch was not given?

I want py2exe to create an interactive session, without writing my own
REPL.

IIRC, in newer Python versions, you can set the PYTHONINSPECT env var inside
your script.

Thomas
 
F

Fuzzyman

In Movable Python I use IPython and code.InteractiveConsole to provide
interactive sessions.

See the file 'movpy.py' in the source distribution to see the code.
Note that to get IPython working with py2exe you must effectively do an
explicit `import site`.
def interactive(localvars=None):
"""A very simple function to embed an interactive interpreter into
movpy."""
# could have the banner passed in as an optional argument, plus
maybe the IPython config file location
IPShellEmbed = None
try:
from IPython.Shell import IPShellEmbed
except ImportError:
pass
if not IPShellEmbed or IPOFF:
if localvars == None:
localvars = sys._getframe(0).f_back.f_locals #
extract locals from the calling frame - taken from IPython
from code import InteractiveConsole
con = InteractiveConsole(localvars)
con.interact()
else:
banner = 'Movable Python\nIPython Interactive Shell. See the
manual for a list of features and tips.\nCtrl-D to exit.'
argv = ['-ipythondir', libdir] # where to find the ipython config file
ipshell = IPShellEmbed(argv, banner=banner)
ipshell()

http://sourceforge.net/projects/movpy
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top