FileNotFoundError:[Errno 2]没有这样的文件或目录 [英] FileNotFoundError: [Errno 2] No such file or directory

查看:958
本文介绍了FileNotFoundError:[Errno 2]没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图打开一个CSV文件,但由于某种原因,python无法找到它。

这是我的代码(这只是一个简单的代码,但我不能解决问题):

 导入csv 

打开('address.csv','r')作为f:
reader = csv.reader(f)
在阅读器中的行:
打印行


解决方案

您正在使用相对路径,这意味着程序将在工作目录中查找该文件。错误是告诉你,在工作目录中没有这个名字的文件。



尝试使用确切的路径或绝对路径。


I am trying to open a CSV file but for some reason python cannot locate it.

Here is my code (it's just a simple code but I cannot solve the problem):

import csv

with open('address.csv','r') as f:
    reader = csv.reader(f)
    for row in reader:
        print row

解决方案

You are using a relative path, which means that the program looks for the file in the working directory. The error is telling you that there is no file of that name in the working directory.

Try using the exact, or absolute, path.

这篇关于FileNotFoundError:[Errno 2]没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆