如何在 python 中自动处理文件
How to automate file handling in python
这是我的代码
f1 = open("file1.txt").read( ).splitlines( )
f2 = open("file2.txt").read( ).splitlines( )
print list(itertools.product(f1,f2))
我想 运行 directory.How 中的所有文件使用 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
这是我的代码
f1 = open("file1.txt").read( ).splitlines( )
f2 = open("file2.txt").read( ).splitlines( )
print list(itertools.product(f1,f2))
我想 运行 directory.How 中的所有文件使用 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