Trouble opening files in python with VS Code

2020-02-15 04:17发布

问题:

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())

回答1:

Try setting

"python.terminal.executeInFileDir": true,

in your VSCode Settings