467,077 Members | 945 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,077 developers. It's quick & easy.

Forcing interactive interpreter without (-i)

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.
--
------------------------------------------------------------------------
Miki Tebeka <mi*********@zoran.com>
http://tebeka.bizhat.com
The only difference between children and adults is the price of the toys
Jul 18 '05 #1
  • viewed: 1601
Share:
2 Replies
Miki Tebeka <mi*********@zoran.com> writes:
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
Jul 18 '05 #2
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

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Dave Reed | last post: by
reply views Thread by Jonas Galvez | last post: by
reply views Thread by Jonas Galvez | last post: by
5 posts views Thread by linuxnow@gmail.com | last post: by
reply views Thread by Simon Eves | last post: by
reply views Thread by Ryan K | last post: by
4 posts views Thread by yan.python@gmail.com | last post: by
3 posts views Thread by R. Bernstein | last post: by
2 posts views Thread by The Pythonista | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.