如何在 python 中自动化文件处理



这是我的代码

f1 = open("file1.txt").read( ).splitlines( )
f2 = open("file2.txt").read( ).splitlines( )
print list(itertools.product(f1,f2))

我想为目录中的所有文件运行它。如何使用python做到这一点。我无法使用 glob 实现此处给出的建议。

import glob
#For any kind of file in that directory.
for file in list(glob.glob("*")):     
# do your work
#For specific kind of file in that directory. like all .py or .txt or .csv file.. etc. 
for file in list(glob.glob("*.file extension")):
# do your work

最新更新