【发布时间】:2017-10-07 12:55:27
【问题描述】:
我的 csv 文件具有以下结构:
ID fromEmail ID toEmail
134 a@a.com 23 b@b.com
33 aa@a.com 323 bbb@b.com
我的 jupyter 笔记本上有以下代码:
import csv as pt
with open(dnc-temporalGraph.csv, 'rb') as f:
data = list(csv.reader(f))
以及以下 NameError:
NameError Traceback (most recent call last)
<ipython-input-65-1b0399e4e4b5> in <module>()
1 import csv as pt
----> 2 with open(dnc-temporalGraph.csv, 'rb') as f:
3 data = list(csv.reader(f))
NameError: name 'dnc' is not defined
我已经检查了一些其他问题,例如 this 和 this,但仍然无法弄清楚我在这里做错了什么。如果我像第二个链接一样将文件名放在单引号之间,那么我会得到一个 IOError
IOError: [Errno 2] No such file or directory: 'dnc-temporalGraph.csv'
请帮忙?
【问题讨论】:
-
使用
with open('dnc-temporalGraph.csv', 'rb'),您忘记了文件名称上的' ' -
不,我没有。阅读上文。
标签: python csv jupyter-notebook nameerror