nanitous
nanitous

Reputation: 711

How to load scripts into a python interpreter session, and letting python start the interactive mode?

I'ld like one of these:

  1. Starting python with a script like python my_routines.py and let python enter the interactive state while the code in my_routines.py have been loaded/run.

  2. Starting python in the interactive mode and loading in some convenient(short and easy to remember) way my_routines.py

the idea is, of course, that I want to preload some stuff and then play around with it in the interactive mode.

Suggestions involving loading a module (python -m ....) don't have to apply ;-)

Looking forward to your ideas!

Twan

Upvotes: 1

Views: 1891

Answers (1)

blue note
blue note

Reputation: 29071

To continue in REPL after running the script, run it with python -i test.py, where -i stands for interactive.

For loading from inside the REPL, you could use exec, but your best bet is to use ipython and its %load command. (ipython is an improved repl, so you should be using that anyway)

Upvotes: 8

Related Questions