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,099
  • 1
  • 18
  • 38

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.
  • 12,804
  • 4
  • 37
  • 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
  • 505
  • 2
  • 7