I tried working on files in python and learned that vsc doesn’t execute the right folder. It executes parental folder instead of sub folder.
highscore.txt has to be in parental folder workspace1 in order for it to work, i want it to be in sub folder snake-game, but then it’s not working
This is the error I get:
FileNotFoundError: [Errno 2] No such file or directory: 'highscore.txt'
Edit: I’m using code runner in order to run code
I changed this setting but it didn’t do anything
I’ve got absolutely no idea how to work on directories, could someone tell me what to change and where to fix it.
2
Answers
I don’t think running a code through a code runner may be problematic, but you should verify to make sure you wrote the right path and that your file is in the game folder.
When you check
Execute in File Dir
, you have to use Run Python File button which provided by Python extension.You can also add
"cwd": "${fileDirname}"
to yourlaunch.json
and use debug mode.If you insist on using the coder-runner extension, please search and check File Directory As Cwd in the settings.