Discussion:
[spyder] Nesting scripts -- runfile to call a script within a script gives KeyError: '__file__' , but run as a selection works fine
p zajonc
2017-12-19 17:53:15 UTC
Permalink
Guidance appreciated. Is there a limitation or a technique needed for
nesting scripts in Spyder?

Script1.py is: print ("hello")

Script2.py is: runfile ('Script1.py')

F9 key runs this line of code fine, the text hello prints out without an
error

F5 key or another script such as Script3.py: runfile ('Script2.py') gives
an error message after printing hello:

hello
Traceback (most recent call last):

File "<ipython-input-24-c314cb3c22a8>", line 1, in <module>
runfile('C:\\Users\\Peter\\Documents\\Roparju
Regression\\Accudata\\Base\\Code\\TESTING Step.py')

File
"C:\Users\Peter\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py",
line 714, in runfile
namespace.pop('__file__')

KeyError: '__file__'


Versions:
python 3.6.1
ipython 6.2.1
conda 4.3.31
spyder 3.2.4
--
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 post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/spyderlib.
For more options, visit https://groups.google.com/d/optout.
Carlos Córdoba
2017-12-19 21:59:12 UTC
Permalink
Hi,

Please open a new issue in our issues tracker

https://github.com/spyder-ide/spyder/issues

with this example so we can better discuss about how to fix this.


Cheers,
Carlos
Guidance appreciated.  Is there a limitation or a technique needed for
nesting scripts in Spyder?
Script1.py is:  print ("hello")
Script2.py is:  runfile ('Script1.py')
F9 key runs this line of code fine, the text hello prints out without
an error
F5 key or another script such as Script3.py:  runfile ('Script2.py') 
hello
  File "<ipython-input-24-c314cb3c22a8>", line 1, in <module>
    runfile('C:\\Users\\Peter\\Documents\\Roparju
Regression\\Accudata\\Base\\Code\\TESTING Step.py')
  File
"C:\Users\Peter\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py",
line 714, in runfile
    namespace.pop('__file__')
KeyError: '__file__'
python 3.6.1
ipython 6.2.1
conda 4.3.31
spyder 3.2.4
--
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
Visit this group at https://groups.google.com/group/spyderlib.
For more options, visit https://groups.google.com/d/optout.
--
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 post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/spyderlib.
For more options, visit https://groups.google.com/d/optout.
Loading...