我已经读过其他的答案了,但似乎我还在某个地方犯错误。你知道吗
我要处理给定目录中的所有csv文件。你知道吗
def main():
data = []
for root, dir, files in os.walk('/Users/me/Documents/ssbm csv/ssbm_stats/'):
for name in files:
# only csv files
if name.endswith(".csv"):
csvpath = os.path.join(root, name)
c = csv.reader(csvpath)
print "processing:", csvpath
games = makeT(c)
它运行,但它做了错误的事情。它不会使用csv.reader()
打开csv文件。你知道吗
def makeT(csvfile):
for row in csvfile:
print csvfile
print row
print len(row)
输出:
<_csv.reader object at 0x10d3ecde0>
['/']
1
长度不对。csv文件的任何部分都没有斜杠字符;因此我认为它可能与文件名有关。我真的不明白为什么它不能正确地传递文件。你知道吗
知道如何将文件名传递给csv.reader()
吗?你知道吗
您需要将实际打开的文件传递给
csv.reader
从文件中
在您的情况下,第一个参数必须是打开的文件
它可以枯萎
或者
但是第二个是首选的,因为它会自动关闭文件。你知道吗
csvreader
对象的其他参数可以包括delimeter
和quotechar
相关问题 更多 >
编程相关推荐