Python出现IndexError: list index out of range

import os
import pandas as pd
import numpy as np

path='C:/Users/310210851/Downloads/Panel Test Raw Data/Optical/Input/'

for root,dirs,files in os.walk(path):
file=root+files[0]
已确认文件夹下面有文件,之前调试成功过,并且手动跑完全没问题,今天自动跑的时候发现报错
Traceback (most recent call last):
File "C:/Work/Data Analysis/Data Parsing/CSV_Parser_Try_Run_2.py", line 10, in <module>
file=root+files[0]
IndexError: list index out of range
不知道出了什么问题,请教大神解释?

你的路径下有空文件夹
这时候files是一个空的列表
因此files[0]会报错
温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-08-11
索引错误,索引值超出范围了
相似回答