当我看到第一个以.txt结尾的文件时,应该使用For循环并中断它吗? While循环似乎不起作用。它一直在继续。它继续按照下面的代码打印文件名。
下面是我正在使用的代码:
import os import pdb asciipath = 'C:\\Users\\rmore\\Desktop\\Datalab' x = 0 file = os.listdir(asciipath) while file[x].endswith('.txt'): print(file[x]) x = x+1