Scripts in editor cannot use pre-existing variables

27 views
Skip to first unread message

LeeEtchels

unread,
Jan 8, 2020, 9:04:50 PM1/8/20
to spyder
Hi all, apologies if this has an obvious fix.

I'm working in Spyder 4 and python 3.7.

If I create a variable in a script (for example a = 5), run it, and then type a into the console it will give back the value 5.

If I create a variable in the console in the same way and then reference it in a script in the editor I get a NameError saying that it hasn't been defined.

The same happens if I run a script from the editor twice, the second run through is incapable of seeing the variables created on the first run (although it can obviously be recreated/defined).

The reason I am trying to work this way is that I am reading in a dataset from a spreadsheet, which takes a while, and then creating plots using the library Bokeh. Once I've read the data in once I want to be able to keep working on the script, making changes and re-running to get all the plots working how I like, without having to import all the raw data again but at the moment the only way I can reference the data that is shown in the variable explorer is through the console.

I'm sure I used to do this in Spyder 3 before I had to get my pc wiped and everything re-installed, but I could be wrong about that.

Is there a setting somewhere that I need to change? I've looked in the preferences but couldn't see anything that I understood as being related...

Thanks very much for any help,
Lee

Carlos Córdoba

unread,
Jan 8, 2020, 9:15:47 PM1/8/20
to spyd...@googlegroups.com
Hi,

To have access to the console namespace when running a file, you need to go to the menu

    Run > Configuration per file

then select the option called "Run in console's namespace instead of an empty one" and finally re-run your file again.


Cheers,
Carlos

El 6/01/20 a las 11:32 a. m., LeeEtchels escribió:
--
You received this message because you are subscribed to the Google Groups "spyder" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spyderlib+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/spyderlib/24ed2b31-0769-4f1e-b1d4-b97c1c2a3fc2%40googlegroups.com.

Philip Yip

unread,
Jan 10, 2020, 5:28:26 PM1/10/20
to spyder
It might be better to have that as a default setting. It caused a bit of confusion for me also when using Spyder 4 for the first time.
Message has been deleted

AD

unread,
Jan 13, 2020, 7:25:27 PM1/13/20
to spyder
I agree with this suggestion.

LeeEtchels

unread,
Jan 13, 2020, 7:25:28 PM1/13/20
to spyder
Thanks a lot, that sorted it :)

Kind regards,
Lee
To unsubscribe from this group and stop receiving emails from it, send an email to spyd...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages