Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing several python files on the same interactive prompt on VS Code

I'm transitioning from Spyder to VS Code, and I'm having an issue executing ad-hoc code on an interactive session. I first save this to a tmp1.py and run the selection on an interactive window:

import pandas as pd

df = pd.DataFrame({'a': [1,2,3,4],
                   'b': [1,1,2,3]})

Then on tmp2.py I just write and run:

print(df)

It opens a new interactive window and complains NameError: name 'df' is not defined. How can I configure it to run on the currently active window / session? Note that I'm not using a Jupyter notebook but IPython.

At some point I'll want to run code in parallel on several terminals, but at first I'd like to get this simple set-up working.

like image 433
NikoNyrh Avatar asked Mar 04 '26 22:03

NikoNyrh


1 Answers

For some reason my "Jupyter > Interactive Window: Creation Mode" setting was "perfile", although "multiple" is supposed to be the default. After changing it to "multiple" everything works logically. I can also open sevaral interactive windows, and the selected code gets evaluated in the active one.

like image 182
NikoNyrh Avatar answered Mar 06 '26 12:03

NikoNyrh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!