Is it possible to start an interactive Python shell inside a Python program?
I want to use such an interactive Python shell (which is running inside my program's execution) to inspect some program-internal variables.
The Python interactive console (also called the Python interpreter or Python shell) provides programmers with a quick way to execute commands and try out or test code without creating a file.
To start the Python language shell (the interactive shell), first open a terminal or command prompt. Then type the command python and press enter. Type "help", "copyright", "credits" or "license" for more information. After the symbols >>> you can type a line of Python code, or a command.
The interactive Python mode lets you run your script instantly via the command line without using any code editor or IDE. To run a Python script interactively, open up your command line and type python. Then hit Enter. You can then go ahead and write any Python code within the interactive mode.
The code module provides an interactive console:
import readline # optional, will allow Up/Down/History in the console import code variables = globals().copy() variables.update(locals()) shell = code.InteractiveConsole(variables) shell.interact()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With