1

Is there a way to execute a Python script, yet stay in the Python shell thereafter, so that variable values could be inspected and such?

7
  • I am not 100% sure if this is what you want, but you could try using the python debugger pdb Commented Aug 14, 2017 at 14:22
  • The IDLE which ships with Python (you still have to download it on Linux) has a built-in debugger. Commented Aug 14, 2017 at 14:22
  • If you just want to run a Python script and have a REPL afterwards, IDLE is really pretty nice. Just open the file, run it, and then you have the REPL already there. Commented Aug 14, 2017 at 14:25
  • Does execfile fit what you need? stackoverflow.com/questions/5280178/… Commented Aug 14, 2017 at 14:26
  • 2
    I think you are looking for python -i ./file.py, where the -i flag will enter interactive mode after executing the file. If you are already in the console, then execfile. Commented Aug 14, 2017 at 14:46

2 Answers 2

1

Metaphox nailed it:

I think you are looking for python -i ./file.py, where the -i flag will enter interactive mode after executing the file. If you are already in the console, then execfile. – Metaphox 2 mins ago

But I want to thank for the other suggestions as well, which go beyond the original question yet are useful!

Sign up to request clarification or add additional context in comments.

Comments

1

For those who use IPython you can use the embed() function for some extra flexibility since it allows you to drop into a shell anywhere in your program:

from IPython import embed

def some_function(args):
    # ... do stuff ...

    embed() # drop to shell here

    # ... back to the function ...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.