我想把一个文件夹中的文件名爬出来,然后这样写的,报错,为什么:
import os
# 遍历文件夹中的文件
path = r"D:\各种模\选股结果"
file_list = []
for i in os.walk ( path ):
if i.endswith('.txt'):
file_list.append ( i )
print ( file_list )
提示这样
C:\Users\大无畏\AppData\Local\Programs\Python\Python36\python.exe "D:/Program Files/JetBrains/PyCharm 2020.2/jbr/bin/D:/PycharmProjects/pythonProject7/get.py"
Traceback (most recent call last):
File "D:/Program Files/JetBrains/PyCharm 2020.2/jbr/bin/D:/PycharmProjects/pythonProject7/get.py", line 8, in
if i.endswith('.txt'):
AttributeError: 'tuple' object has no attribute 'endswith'
Process finished with exit code 1