我使用python3对csv文件进行排序,代码如下。它在MAC上运行得很好,但在Windows(real或Fusion)上我遇到了这个例外。有人看到这个或者有什么建议吗?在
Exception in Tkinter callback Traceback (most recent call last):
File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__
return self.func(*args)
File "Z:\bin\FDTSEfiles\HrsWonVal.py", line 470, in <lambda>
Button(newOrExisting, text="OK", command=lambda: getnewOrExisting_File(U_cmd.get())).grid(row=5, column=1)
File "Z:\bin\FDTSEfiles\HrsWonVal.py", line 466, in getnewOrExisting_File
reverseOrderAndFilterFile(existingFilePath)
File "Z:\bin\FDTSEfiles\HrsWonVal.py", line 510, in reverseOrderAndFilterFile
sortedlist = sorted(data, key=operator.itemgetter(3))
# 3 specifies the 4th column - Date IndexError: list index out of range
我的代码:
^{pr2}$
csv
模块docs中的脚注:Windows恰好是一个(…the)平台,它使用
\r\n
作为行结尾。这就是为什么要获得特定于平台的行为;通过将newline=''
指定到open
来删除它。在无论平台是什么,
sorted
都能正常工作。回溯告诉您错误发生的确切位置,显然这与您的数据不是您认为的那样(或者没有被csv模块解释为)有关-要么定界符错误,要么源文件的列少于四列。在相关问题 更多 >
编程相关推荐