Start the interactive shell within an application

  • Thread starter Jean-Michel Pichavant
  • Start date
J

Jean-Michel Pichavant

I was wondering if there is a way to start an interactive shell within a
script/application.
I'm sometimes tired of adding prints to scan the current namespace so
I'd like to pause the execution and give the user the shell prompt.
This is obviously for debugging purpose.

I know that I may use the raw_input and eval the captured text but
honestly, this requires some coding and I won't benefit from the shell
features. Would it be even possible to use a shell like Ipython ?

By the way, if anyone has cunning ways for debugging code to share, he
would be much welcome.

Jean-Michel
 
E

eGlyph

I'm sometimes tired of adding prints to scan the current namespace so
I'd like to pause the execution and give the user the shell prompt.
This is obviously for debugging purpose.

This is definitely doable, have look at rhythmbox or gedit - they
provide an interactive console.
Also, have a look at IPython, they have a recipe and an example of
embedding IPython into a user's application.
 
J

Javier Collado

Take a look either at code.interact or at
IPython.ipapi.launch_new_instance. Basically, the only thing that you
have to provide is a dictionary object that contains the namespace
that you would like to have in your shell once it's launched.

Best regards,
Javier
 
B

Ben Charrow

If you're looking to debug your program, try "import pdb" and then wherever you
want to debug put:

pdb.set_trace()

Your program will then enter the debugger when it executes that line. It's
quite nice really. If you get confused on what to do, just type "help"

http://docs.python.org/library/pdb.html

Cheers,
Ben
 
A

alex23

If you're looking to debug your program, try "import pdb"

Another option, if you wish to debug an error, is to run python using
the -i parameter. This will leave you inside the interpreter at the
point that execution stops. Very handy.

- alex23
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top