在不使用任何库的情况下将 zip 列表转换为 txt 文件
Convert zip lists to a txt file without using any libraries
for (a, b, c, d, e, f, g) in zip(A, B, C, D, E, F, G):
result = ''.join([a,b,c,d,e,f,g])
# Write the file
with open("file.txt","w") as f:
f.write(result)
这只给出了一行而不是整个结果。结果的类型如下所示。我可以知道如何将整个结果转换为 txt 文件吗?非常感谢。
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
你需要在循环中调用f.write(result)
。并在每一行后附加一个换行符。
with open("file.txt","w") as f:
for data in zip(A, B, C, D, E, F, G):
result = ''.join(data)
f.write(result + '\n')
如果您只是想将压缩元组组合回列表中,则无需将压缩元组散布到变量中。直接使用元组即可。
for (a, b, c, d, e, f, g) in zip(A, B, C, D, E, F, G):
result = ''.join([a,b,c,d,e,f,g])
# Write the file
with open("file.txt","w") as f:
f.write(result)
这只给出了一行而不是整个结果。结果的类型如下所示。我可以知道如何将整个结果转换为 txt 文件吗?非常感谢。
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
你需要在循环中调用f.write(result)
。并在每一行后附加一个换行符。
with open("file.txt","w") as f:
for data in zip(A, B, C, D, E, F, G):
result = ''.join(data)
f.write(result + '\n')
如果您只是想将压缩元组组合回列表中,则无需将压缩元组散布到变量中。直接使用元组即可。