Python CSV:列表索引超出范围

Python CSV:列表索引超出范围,python,csv,Python,Csv,我遇到了一个脚本问题,我没能解决。我对编码相当陌生,我继承了这个脚本。我读过这个问题的其他答案,但是他们的代码看起来很不一样,有些解决方案不起作用。代码如下: def CopyFileType(path): for file in glob.glob(stage_dir + path): csvfile = open(file,'rb') csvFileArray = [] #Line Commented Out - Needed for

我遇到了一个脚本问题,我没能解决。我对编码相当陌生,我继承了这个脚本。我读过这个问题的其他答案,但是他们的代码看起来很不一样,有些解决方案不起作用。代码如下:

def CopyFileType(path):
    for file in glob.glob(stage_dir + path):
        csvfile = open(file,'rb')
        csvFileArray = []
        #Line Commented Out - Needed for Python 2
        #for row in csv.reader(csvfile, delimiter = '\t'):        
        for row in csv.reader(codecs.iterdecode(csvfile, 'utf-8'), delimiter = '\t'):                   
            csvFileArray.append(row)

        string=str(csvFileArray[0])
        c=string.find('Value (en)')
        csvfile.close()
        if c>0:
            shutil.move(file,dest_dir2)
        else:
            shutil.move(file,dest_dir1)
下面是错误报告:

D:\Python>C:/Python373/python.exe d:/Python/New_Data_Extract.py
Traceback (most recent call last):
  File "d:/Python/New_Data_Extract.py", line 73, in <module>
    CopyFileType(r'\*_SC_*.txt')
  File "d:/Python/New_Data_Extract.py", line 37, in CopyFileType
    string=str(csvFileArray[0])
IndexError: list index out of range
D:\Python>C:/Python373/Python.exe D:/Python/New\u Data\u Extract.py
回溯(最近一次呼叫最后一次):
文件“d:/Python/New_Data_Extract.py”,第73行,在
CopyFileType(r'\*\u SC.*.txt')
CopyFileType中的文件“d:/Python/New_Data_Extract.py”,第37行
string=str(csvFileArray[0])
索引器:列表索引超出范围
我会诚实地说,我不完全确定脚本在做什么,但我希望有人能发现一些明显的、容易修复的东西?任何见解或想法都会非常有用


我想知道问题是否与它正在读取的文件有关,但我不确定要查找什么

您的
阅读器
不会返回任何结果,因此不会向该列表添加任何内容“def CopyFileType(path):对于glob.glob(stage_dir+path)中的文件:”粘贴时缩进丢失,抱歉@Sayse你能解释一下你的意思吗?对不起,谢谢,我会看看它有什么作用的,汉克斯,我会尝试一下,看看我能不能把它分离出来。