strange behavior with cell
See original GitHub issueIt might be an ipython issue or something… but for me it is highly puzzling.
Problem Description
Here is a reproducible example
from math import sqrt
# %%
# run this cell before the file, it will normally crashed (lack of sqrt)
# then run whole file
# then call in ipython console: foo2(); print(x)
# x is still 1 !!!
def foo1():
global x
x=sqrt(1)
def foo2():
global x
x=sqrt(4)
foo1()
What steps reproduce the problem?
- run the cell 1st, will normally crash
- run the file
- call in the console: foo2()
- print(x)
What is the expected output? What do you see instead?
‘x’ should be 2, while ‘x’ is still 1
if one reruns the cell, then now it is fine. It is like there are different namespaces or globals for cells ??? It is weird and sources of crazy bugs. Thanks. I guess I’ve default settings in ‘run’ & ‘python interpreter’.
Versions
- Spyder version: 6.0.0.dev0 48b930506
- Python version: 3.8.9 64-bit
- Qt version: 5.15.2
- PyQt5 version: 5.15.4
- Operating System: Windows 10
Issue Analytics
- State:
- Created 2 years ago
- Comments:24 (24 by maintainers)
Top Results From Across the Web
Strange behavior: New study exposes living cells to ... - Phys.org
Strange behavior: New study exposes living cells to synthetic protein. John Chaput is a researcher in ASU's Biodesign institute Photo by: ...
Read more >Strange behavior: new study exposes living cells to synthetic ...
Strange behavior: new study exposes living cells to synthetic protein ... Inside the cell, DX proteins bind with molecules of ATP, ...
Read more >EXCEL 365: Filtered view, strange behavior.
When in filtered view I have noticed 3 issues. 1. One cannot just copy some cells from a coloumn into a sheet with...
Read more >AN UNUSUAL BEHAVIOR OF STRAIN HELA CELLS ... - NCBI
J Cell Biol. ... AN UNUSUAL BEHAVIOR OF STRAIN HELA CELLS IN TISSUE CULTURE ... A description of cellular emigration of embryo chick-leg...
Read more >Excel Vba Abnormal Behavior of Cells.Find on Merged Cells
The abnormal behavior I'm experiencing is that Find always returns the cell as Nothing on my second call of the sub (The cells...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for these observations & your interest. Yes checking option 2 in ‘run’ does the job. But I am wondering what the opposite (option 2 not checked) means for cells?
My naive understanding of running a cell is: just populate/update the console namespace with the content of the cell; while a file could be seen as a list of cells (with different inputs or knowledge depending on the run option above). If it does something else, it should be stated clearly I guess.
IMHO, there is still a bug when option 2 is unchecked. I’ve found out that even running the file to start with (instead of the cell first) leads to the same problem ; and removing the cell ie ‘# %%’ does not help. It might be due to declaring the variable x from the functions and not from the global namespace ???
But indeed, checking option 2, solves all these experiments, which is even weirder when starting from scratch (because the console is empty anyway!).
Thanks.
Maybe we could simply add a warning when someone runs code in an empty namespace that contains “global”