Happysmithers
Happysmithers

Reputation: 761

Run Python console after script execution in same environment

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?

Upvotes: 1

Views: 496

Answers (2)

Hannes Ovrén
Hannes Ovrén

Reputation: 21831

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 ...

Upvotes: 1

Happysmithers
Happysmithers

Reputation: 761

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!

Upvotes: 1

Related Questions