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)
This only gives one line instead of the whole result. The type of the result is shown below. May I know how to convert the whole result to a txt file? Thanks a lot.
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
You need to call f.write(result)
in the loop. And append a newline to each line.
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')
There's no need to spread the zipped tuples into variables if you're just going to combine them back into a list. Just use the tuples directly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.