我为这个简单的问题挣扎了太久,所以我想我应该寻求帮助.我正在try 将国家医学图书馆ftp站点上的期刊文章列表读入Python 3.3.2(在Windows 7上).杂志上的文章都在一个小册子里.csv文件.
我try 了以下代码:
import csv
import urllib.request
url = "ftp://ftp.ncbi.nlm.nih.gov/pub/pmc/file_list.csv"
ftpstream = urllib.request.urlopen(url)
csvfile = csv.reader(ftpstream)
data = [row for row in csvfile]
它会导致以下错误:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
data = [row for row in csvfile]
File "<pyshell#4>", line 1, in <listcomp>
data = [row for row in csvfile]
_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)
我想我应该使用字符串而不是字节?对于简单问题的任何帮助,以及出现问题的原因的解释,我们将不胜感激.