Forcing interactive interpreter without (-i)

Fuzzyman fuzzyman at gmail.com
Tue Feb 1 05:40:18 EST 2005


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




More information about the Python-list mailing list