Start a python interactive shell from python.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bo Peng

    #1

    Start a python interactive shell from python.

    Dear list,

    This may sound strange but I need to start a python shell from python.
    The motivation is that I have a bunch of (numeric) python functions to
    provide to a user. The best way I can think of is packing my python
    module using py2exe, and because it is easiest to let him run the
    functions through python syntax, I would like to start a python shell
    after the module is loaded.

    Something like:

    def myfunc(a):
    pass

    if __name__ == '__namin__':
    ' myfunc has been defined '
    START A PYTHON SHELL?

    so the user can type myfunc(0.5) and others. I can of course use
    raw_input and eval but I will lose the convenience of a real shell.

    Many thanks in advance.
    Bo
  • Bo Peng

    #2
    Re: Start a python interactive shell from python.


    I think I find what I need:



    Bo

    Comment

    • Fernando Perez

      #3
      Re: Start a python interactive shell from python.

      Bo Peng wrote:
      [color=blue]
      >
      > I think I find what I need:
      >
      > http://aspn.activestate.com/ASPN/Coo.../Recipe/355319[/color]

      That's a nice, lightweight one. Note that if you want to have all the bells
      and whistles of ipython (and you have ipython already), then a simple

      if __name__ == '__namin__':
      from IPython.Shell import IPShellEmbed
      ipshell = IPShellEmbed()
      ipshell() # this call anywhere in your program will start IPython

      will do. You'll find all the details on how to customize ipython for this kind
      of task here:



      Given ipython's threading capabilities, you can even instantiate this with
      proper thread support in case you want to be able to use matplotlib (or any
      other GUI toolkit) interactively. Neither the ASPN recipe, nor anything in the
      stdlib, will give you this.

      Feel free to stop by the ipython-user list if you have more questions: I don't
      monitor c.l.py regularly so I may miss threads or replies here.

      Cheers,

      f

      Comment

      Working...