我试图创建一个拉格雷htb文件的许多小的htb文件。到目前为止,我可以创建一个包含目录中所有文件内容的列表。如何再次将我的列表保存到htb文件?你们有人能帮我吗?到目前为止,我的代码如下:
import os
folderpath = r"C:/Users/l-reh/Desktop/HTB"
filepaths = [os.path.join("C:/Users/l-reh/Desktop/HTB/", name) for name in os.listdir(folderpath)]
all_files = []
for path in filepaths:
with open(path, 'r') as f:
file = f.readlines()
all_files.append(file)发布于 2021-04-12 21:49:53
可以使用itertools.chain.from_iterable()连接列表的嵌套列表
>>> from itertools import chain
>>> all_files = [["this is some", "content"], ["this", "is more stuff"], ["and", "more and", "more"]]
>>> newfile_contents = "\n".join(chain.from_iterable(all_files))
>>> print(newfile_contents)
this is some
content
this
is more stuff
and
more and
morehttps://stackoverflow.com/questions/67059105
复制相似问题