Reputation: 51
I can't seem to open basic text files when I run a python script in VS Code, the code runs fine when I use it in Idle but VSCode will give me a FileNotFound error, is there some sort of extension that allows me to do this? Right now I'm only using the Python and Code Runner extension. example of my code:
def getInput(textFile):
file=open(textFile,'r')
print(file.readlines())
Upvotes: 5
Views: 23456
Reputation: 61
Whenever you need to debug, you need to change the path of the file to open it in debug mode by simply:
That should help you!
Upvotes: 1
Reputation: 408
In your VSCode for Windows
File --> Preferences --> Settings --> (User)Extensions --> Python -->
Terminal: Execute In File Dir --> Check It
or
File --> Preferences --> Settings --> Search Settings --> python.terminal.executeInFileDir
Upvotes: 6
Reputation: 957
Try setting
"python.terminal.executeInFileDir": true,
in your VSCode Settings
Upvotes: 15