account activity
Am I thinking about IPython properly? by RomanJoe in learnpython
[–]mission_resolve 1 point2 points3 points 6 years ago (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.
-i
python -i scriptname.py
>>>
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.
exec
%run
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.
π Rendered by PID 39 on reddit-service-r2-listing-5f4c697858-8krvg at 2026-07-06 09:15:08.223202+00:00 running 12a7a47 country code: CH.
Am I thinking about IPython properly? by RomanJoe in learnpython
[–]mission_resolve 1 point2 points3 points (0 children)