我有一个文件夹,有1000个txt文件。如果文件中有数据,我的代码工作得很好。
在我的代码中有没有构建逻辑来检查文件是否为空,如果为空则跳到下一个?
import glob
import os
path = 'path/to/file'
for filename in glob.glob(os.path.join(path, '*.txt')):
with open(filename, 'r',encoding='ISO-8859-1') as f:
print(filename)
text = f.read()
do other stuff