Issue
When I open Spyder (version 4.1.4), it opens a script that I was previously working with. However, the directory is set to 'C:\\Users\\UserName'
(this is what I get with os.getcwd()
).
I like to change the directory to where the script is, but I couldn't find a simple way to get the directory of the script and use os.chdir(path)
.
As it's mentioned here, os.path.dirname(__file__)
gives NameError: name '__file__' is not defined
when I run it on Spyder console, and I like to get the path without running the whole script.
In Spyder, what command(s) can I use to find a currently opened script?
Solution
I haven't found a solution either. This is the way I deal with it on Windows:
- Select and comment the whole script (Ctrl + a + Ctrl + 1)
- Run file (F5)
- Uncomment or undo (Ctrl + z).
At least in my case, the current directory changes to that of the script.
Answered By - Joan Barreto
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.