【发布时间】:2017-06-08 04:20:16
【问题描述】:
我正在编写一个脚本来读取 csv 文件。 csv 文件和脚本位于同一目录中。但是当我试图打开文件时,它给了我FileNotFoundError: [Errno 2] No such file or directory: 'zipcodes.csv'。我用来读取文件的代码是
with open('zipcodes.csv', 'r') as zipcode_file:
reader = csv.DictReader(zipcode_file)
如果我提供文件的完整路径,它将起作用。为什么open() 需要文件的完整路径?
【问题讨论】:
-
什么是
os.getcwd()?如果该目录与包含文件的目录不同,则相对路径不起作用。 -
因为您在其他目录中运行 python 脚本,而 that 是您的当前目录。
-
我在 Visual Studio 代码调试器中运行代码。
-
...它当前的工作目录是什么?
标签: python file visual-studio-code python-3.4