user6695701
user6695701

Reputation: 337

Variable problem on ipython console of python 3 in spyder

Recently I'm considering using mainly python 3 although I have used python 2.7 so far.
But I encountered variable problem on python 3 as follows.

For example, the below code properly works in python 2.

#print a 
a=1

I run the code named test.py many times on ipython console (python 2.7.16) in spyder 3.3.6. After the first run, I remove # in the first line. Then, ipython console outputs 1 which is a's value.

However, when I run the above code (the first line is replaced by #print(a)) similar to the above on ipython console (python 3.7.6) in spyder 4.0.1, ipython console outputs an error message, NameError: name 'a' is not defined.
When I input a in the ipython console, the console outputs 1.

Can I do the same thing in my python 3 environment as I do in python 2?

Thank you in advance.

Upvotes: 2

Views: 1025

Answers (1)

BarNiy
BarNiy

Reputation: 88

There is a setting when running the script called "Run in console's namespace instead of an empty one". If you tick that box it keeps the variables in the namespace.

Upvotes: 3

Related Questions