|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- def search_files(key, detail):
- all_files = os.walk(os.getcwd())
- txt_files = []
- for i in all_files:
- for each_file in i[2]:
- if os.path.splitext(each_file)[1] == '.txt': # 根据后缀判断是否文本文件
- each_file = os.path.join(i[0], each_file)
- txt_files.append(each_file)
复制代码
请问,第五行的 i[2] 是什么意思呢?
本帖最后由 jackz007 于 2020-3-5 11:19 编辑
os . walk() 一般是这么用的
- for path , dirs , files in os . walk(os . getcwd())
复制代码
如此看来,代码中的
- all_files = os.walk(os.getcwd())
- . . . . . .
- for i in all_files:
- for each_file in i[2]:
复制代码
i = [path , dirs , files]
i[0] : 是 path, 当前目录
i[1] : 是 dirs, 子目录列表
i[2] : 是 files, 文件列表
|
|