Re: Start a python interactive shell from python.

2006-01-26 Thread Bo Peng

I think I find what I need:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/355319

Bo
-- 
http://mail.python.org/mailman/listinfo/python-list


Start a python interactive shell from python.

2006-01-26 Thread Bo Peng
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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Start a python interactive shell from python.

2006-01-26 Thread Fernando Perez
Bo Peng wrote:

 
 I think I find what I need:
 
 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/355319

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:

http://ipython.scipy.org/doc/manual/node9.html

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

-- 
http://mail.python.org/mailman/listinfo/python-list