skip to Main Content

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

XX

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

it is enabled

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


  1. 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.

    Login or Signup to reply.
  2. When you check Execute in File Dir, you have to use Run Python File button which provided by Python extension.

    enter image description here

    You can also add "cwd": "${fileDirname}" to your launch.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.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search