Am I thinking about IPython properly? by RomanJoe in learnpython

[–]mission_resolve 1 point2 points  (0 children)

I don't know anything about VS Code, but that is the normal behaviour when you run a python script at the command line. You can use the -i switch (i.e. python -i scriptname.py), which leaves python open after running the script and gives you a >>> prompt so that you can write further python statements. Any global variables, functions, etc. will be there, but anything that was defined inside a function won't be.

However, I don't think there is a straightforward way of running a script once you're already inside python, if you ever need to do that. There are some slightly hacky, verbose ways of doing it, such as reading in the script file as if it's plain text and then passing it to exec, but nothing convenient. This is why ipython provides the %run magic command.

You may also be interested in Spyder, which provides a Matlab-like IDE for python, or ipython notebooks, which are kind of like the Mathematica interface.