0

The shortcut I created runs the program fine like such in the bottom right, however when I run it through VSCODE it gives me an error saying that it cannot find the file which is strange because this program worked fine both ways until I moved the file location. <<REFERENCE PICTURE FOR MORE INFO>>enter image description here

I have tried copying every type of path and modifying it in the open('stats.txt') however nothing works any ideas? I can post the full code if necessary however I really do not think this is a code issue.

Michael
  • 1
  • 2
  • Where is the "stats.txt" file located? Type `cd C:\path\to\folder\of\file\goes\here` in the vscode terminal and hit enter to change the current directory. That way, when the command is run and `open("stats.txt")` looks in the current directory, the current directory will have the file. – Dennis Dec 17 '22 at 04:07
  • Note the difference between "current working directory" versus "location of the python file". See https://stackoverflow.com/questions/5137497/find-the-current-directory-and-files-directory – Dennis Dec 17 '22 at 04:10
  • Dennis I hope you see this, I am new to python and coding in general. When I change the code to this ```Scripts\Projects\Stock Project\Stock Related\stats.txt``` path type it will work in VSCODE but then my shortcut stops working. It worked previously in both "terminals"? should I just leave it so the shortcut works since that is what I need? or is there a way to fix this? – Michael Dec 17 '22 at 04:17
  • Either (1) use the trick from the link I sent involving `__file__` to look for files in the same directory as the `.py` file, or (2) reconfigure your shortcut (go to "properties" > "start in...") to open the correct path as the current working directory. – Dennis Dec 17 '22 at 04:22

0 Answers0