Reputation: 3247
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
Upvotes: 0
Views: 153
Reputation: 14369
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.
Upvotes: 3
Reputation: 525
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
Upvotes: 2