0

I'd like to run a script which does some setup then opens up a shell with that environment. So rather than then doing

$ python
>>> # do some setup
>>> # start doing what I really came here to do

I want to do

$ python my_script.py
>>> # start doing what I really came here to do
Alexander Soare
  • 2,825
  • 3
  • 25
  • 53

2 Answers2

3

Run your script with the -i argument:

python -i my_script.py

This will execute my_script.py and drop to an interactive shell afterwards.

Klaus D.
  • 13,874
  • 5
  • 41
  • 48
2

you can do some thing like this

import code

variables = {"test": True}
shell = code.InteractiveConsole(variables)
shell.interact()

now it will open python shell and you can access test variable directly

jaswanth
  • 515
  • 2
  • 7