import os
import glob
def remove_newlines(fname):
flist = open(fname).readlines()
return [s.rstrip('\n') for s in flist]
my_file=open("all_content_file.txt", "w")
for i in glob.glob('./*.txt'):
my_file.write("path")
my_file.write(os.path.abspath(i))
my_file.write(" ")
for j in remove_newlines(os.path.abspath(i)):
my_file.write(j)
my_file.write(" ")
my_file.write("\n")
请尝试以下代码。也许对你有帮助
相关问题 更多 >
编程相关推荐