473,785 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Jan 26 '06 #1
2 2005

I think I find what I need:

http://aspn.activestate.com/ASPN/Coo.../Recipe/355319

Bo
Jan 26 '06 #2
Bo Peng wrote:

I think I find what I need:

http://aspn.activestate.com/ASPN/Coo.../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

Jan 26 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3504
by: Dave Reed | last post by:
I seem to remeber reading somewhere there was a statement you could put in your python program to stop its execution and start the interactive interpreter at that point (and then you could change the value of some variables and continue executing). Am I having delusions or is there a way to do this? Thanks, Dave
11
5043
by: ronan_boisard | last post by:
hi all, I'm trying to call ksh script from python. I have a file (toto.env) with a scirpt looking like: -- begin --- #!/bin/ksh # export TOTO_ENV=/home/toto -- end ---
16
3095
by: diffuser78 | last post by:
I want to write a python program and call OS specific commands in it. So basically, instead of typing in on the command line argument I want to have it in a python program and let it do the action. for example. in my program I would want to call the ssh feature like one does on the command line ssh Admin@192.168.2.10 .....etc How can I do this easily ?
7
1351
by: Michael R. Copeland | last post by:
I've decided that Python is a language/environment I'd like to learn (I've been a professional programmer for 45+ years), but I really don't know where and how to start! I have a number of books - and am buying some more - but because of the bewildering number of after-market packages, environments, and add-ons, I am really quite perplexed about starting. 8<{{ Yes, I could fire up the interactive mode and play with some statements...but...
3
1884
by: R. Bernstein | last post by:
The next release of pydb will have the ability to go into ipython from inside the debugger. Sort of like how in ruby-debug you can go into irb :-) For ipython, this can be done pretty simply; there is an IPShellEmbed method which returns something you can call. But how could one do the same for the stock python interactive shell? To take this out of the realm of debugging. What you want to do is to write a python program that goes...
6
954
by: notnorwegian | last post by:
when running a very computationalheavy program in the shell it sometimes freezes but the commandprompt runs it without problems and muh faster, why? also, the command prompt starts at C:\Users\user> i want to start at C:\python25\progs how do i change that?
3
3952
by: mmm | last post by:
I am looking for advice on Python Editors and IDEs I have read other posts and threads on the subject and my two questions at this time are mainly about the IDLE-like F5-run facilities. While I am fairly happy using IDLE, the debugger is unintuitive to me and I wanted a project manager and a better variable/ class browser and also the potential to edit/run other languages such as R and Tex/Latex. Windows and LINUX compatibility is...
8
5583
by: james.kirin39 | last post by:
Hi everyone, After having used Python on Linux for some time, I now have to do Python coding on Windows. I am big fan of the interactive Python shell to test, eg, regexps. Is there an interactive Python shell on Windows that supports: - easy copy-pasting to/from an editor? (as opposed to the cumbersome "mark", "copy" and then "paste" sequence that any terminal on Windows
9
15536
by: Catherine Moroney | last post by:
I have one script (Match1) that calls a Fortran executable as a sub-process, and I want to write another script (Match4) that spawns off several instances of Match1 in parallel and then waits until they all finish running. The only way I can think of doing this is to call it as a sub-process, rather than directly. I'm able to get Match1 working correctly in isolation, using the subprocess.Popen command, but calling an instance of Match1...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7510
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4063
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.