FileNotFoundError Python Script

强颜欢笑 提交于 2019-12-13 08:20:38

问题


I am trying to run a python script, .py in the windows command prompt.

I drag the script from my files into the command prompt window. I run it. Then, the script presents a prompt for me to enter the file I would like to parse. I am supposed to enter a file like this: filename.txt

When I go to do this, I get the FileNotFoundError. They are both located in my downloads folder. Any ideas as to why? I've tried a couple of things but having no luck.

The script must be performed this way because this is a script many people will use and it is likely that they will receive it and download it and the file to parse to their computer so it'll be located in their downloads folder.

When I created the script I did it in Notepad++ and had a separate folder where I put the file and script and it worked fine this way. I am just ensuring it works from the perspective of someone who's downloading it off an email or website, etc.

Thanks !


回答1:


Yeah that happened to me a lot.

To solve it just write the whole directory of the file.

If you are in windows

c:\user\username\Desktop\file.txt

If you are in linux or mac:

/home/username/Desktop/file.txt


来源:https://stackoverflow.com/questions/51900640/filenotfounderror-python-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!