Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何读取Python的csv文件脚本?_Python_Django_Csv - Fatal编程技术网

如何读取Python的csv文件脚本?

如何读取Python的csv文件脚本?,python,django,csv,Python,Django,Csv,如何读取Python的csv文件脚本 import csv with open('some.csv', 'rb') as f: reader = csv.reader(f) for row in reader: print row 给出了这个错误 python2 test.py Traceback (most recent call last): File "test.py", line 1, in <module> import csv File "/home

如何读取Python的csv文件脚本

import csv
with open('some.csv', 'rb') as f:
  reader = csv.reader(f)
  for row in reader:
     print row
给出了这个错误

python2 test.py 
Traceback (most recent call last):
File "test.py", line 1, in <module>
import csv
File "/home/miruss/virtualbox/csv.py", line 4, in <module>
  f = open(sys.argv[1], 'rt')
IndexError: list index out of range
python2 test.py
回溯(最近一次呼叫最后一次):
文件“test.py”,第1行,在
导入csv
文件“/home/miruss/virtualbox/csv.py”,第4行,在
f=打开(sys.argv[1],'rt')
索引器:列表索引超出范围
我不理解错误的原因

print list(csv.reader(open("somefile.csv")))
我想你的错误来自于“sys.argv[1]”,这样行吗

您打算根据文件名执行代码


python2 test.py filename.csv

Emm。。。错误与您的脚本不匹配您可能希望使用重现问题所需的代码片段编辑您的帖子。很好地了解到他的问题与csv无关…python2 test.py some.csv Traceback(最近一次调用最后一次):导入csv文件中的文件“test.py”,第1行“/home/miruss/virtualbox/csv.py”,第6行,在reader=csv.reader(f)AttributeError中:“module”对象没有属性“reader”