This is an odd issue that popped up after upgrading to 4.0.0
When I run a script again with F5 that has been run previously in the same console (with F5 or F9), then the running script does not recoginze previously created variables in locals() while running it with F9 or manually entering code does recognize those variables.
Note that the option to delete all variables before running a script is turned OFF!
Run this code twice with F5:
print("test" in locals())
if "test" not in locals():
test = 1
print("assigned test")
The output will always be:
assigned test
Running it twice with F9 instead yields
assigned test
on the first run and
on the second run as expected.
Now run the code the second time with F5 as follows, that is interrupt it with an Exception:
print("test" in locals())
assert False
if "test" not in locals():
test = 1
print("assigned test")
The first print statement will return False
yet manually entering print("test" in locals())
directly after the exception returns True
.
cloudpickle >=0.5.0 : 1.2.2 (OK)
pygments >=2.0 : 2.5.2 (OK)
qtconsole >=4.6.0 : 4.6.0 (OK)
nbconvert >=4.0 : 5.6.1 (OK)
sphinx >=0.6.6 : 2.2.2 (OK)
pylint >=0.25 : 2.4.4 (OK)
psutil >=0.3 : 5.6.7 (OK)
qtawesome >=0.5.7 : 0.6.0 (OK)
qtpy >=1.5.0 : 1.9.0 (OK)
pickleshare >=0.4 : 0.7.5 (OK)
zmq >=17 : 18.1.1 (OK)
chardet >=2.0.0 : 3.0.4 (OK)
numpydoc >=0.6.0 : 0.9.1 (OK)
spyder_kernels >=1.8.1;<2.0.0: 1.8.1 (OK)
qdarkstyle >=2.7 : 2.7 (OK)
atomicwrites >=1.2.0 : 1.3.0 (OK)
diff_match_patch >=20181111 : 20181111 (OK)
intervaltree : None (OK)
watchdog : None (OK)
keyring : None (OK)
pexpect >=4.4.0 : 4.7.0 (OK)
pympler : None (OK)
sympy >=0.7.3 : 1.4 (OK)
cython >=0.21 : 0.29.14 (OK)
IPython >=4.0 : 7.10.1 (OK)
matplotlib >=2.0.0 : 3.1.2 (OK)
pandas >=0.13.1 : 0.25.3 (OK)
numpy >=1.7 : 1.17.3 (OK)
scipy >=0.17.0 : 1.3.1 (OK)
pyls >=0.31.2;<0.32.0 : 0.31.2 (OK)
rtree >=0.8.3 : 0.9.1 (OK)
I think this is related to this option. Could you check and report back please?
@Khris777 This by design in the new spyder 4. Following the default behavior of ipython's %run. Currently by default spyder now executes file in a clean namespace and then copies the variable from the namespace into the console namespace. This gives the advantage for not having to worry about difficult to detect bugs in scripts that will depend on order of execution, and the scripts will work outside of spyder the same as they do inside.
For the most part I think that using code cells is a nicer solution running multiple things, but I have made some quick and dirty scripts before using two files.
So with that in mind can disabled this feature globally as @jnsebgosselin suggested or on a per file basis(this is the "safer" option) using the run configuration per file
(ctrl-F6).
I'm going to close this issue but it this doesn't cover it for your use case feel free to reopen.
@jnsebgosselin
You were correct, checking this option restored the old behaviour I was used to, thanks for the info.
Most helpful comment
@Khris777 This by design in the new spyder 4. Following the default behavior of ipython's %run. Currently by default spyder now executes file in a clean namespace and then copies the variable from the namespace into the console namespace. This gives the advantage for not having to worry about difficult to detect bugs in scripts that will depend on order of execution, and the scripts will work outside of spyder the same as they do inside.
For the most part I think that using code cells is a nicer solution running multiple things, but I have made some quick and dirty scripts before using two files.
So with that in mind can disabled this feature globally as @jnsebgosselin suggested or on a per file basis(this is the "safer" option) using the
run configuration per file
(ctrl-F6).I'm going to close this issue but it this doesn't cover it for your use case feel free to reopen.