将 zip 对象垂直写入 .txt 文件
我在 python 中有几个 zip 对象,如下所示:
list(zipped1)
Out[84]:
[(0, 2),
(0, 3),
(0, 5),
(0, 782139),
(0, 913408),
(0, 956747),
(0, 970377),
(0, 1012808),
(0, 3036503),
(0, 7112396),
(0, 7436273),
(0, 7454654),
(0, 7460688),
(0, 8603961)]
list(zipped1)
Out[84]:
[(0, 782139),
(0, 913408),
(0, 956747),
(0, 970377),
(0, 1012808),
(0, 3036503),
(0, 7112396)]
我有一个此对象的列表 zippeds
我想将 zip 对象写入一个垂直连接的单个文本文件中,不使用逗号,但使用空格,如下所示
0 2
0 3
0 5
0 782139
0 913408
0 956747
0 970377
0 1012808
0 3036503
0 7112396
0 7436273
0 7454654
0 7460688
0 8603961
0 782139
0 913408
0 956747
0 970377
0 1012808
0 3036503
....
:第一列中的零并不总是如此,只是巧合,它们全部都是零。我在使用文件 I/O 方面没有太多经验,而且我不知道如何破解这个问题。任何帮助\指导将不胜感激!
I have several zip objects in python like this:
list(zipped1)
Out[84]:
[(0, 2),
(0, 3),
(0, 5),
(0, 782139),
(0, 913408),
(0, 956747),
(0, 970377),
(0, 1012808),
(0, 3036503),
(0, 7112396),
(0, 7436273),
(0, 7454654),
(0, 7460688),
(0, 8603961)]
list(zipped1)
Out[84]:
[(0, 782139),
(0, 913408),
(0, 956747),
(0, 970377),
(0, 1012808),
(0, 3036503),
(0, 7112396)]
And I have a list of this objects zippeds
I want to write the zip objects in a single text file concatenated vertically without the commas but with spaces like this:
0 2
0 3
0 5
0 782139
0 913408
0 956747
0 970377
0 1012808
0 3036503
0 7112396
0 7436273
0 7454654
0 7460688
0 8603961
0 782139
0 913408
0 956747
0 970377
0 1012808
0 3036503
....
Noted that the zeros in the first column is not always the case, just coincidence that all of them are zeros. I haven't much experience in working with file I/O and I can't figure out how to crack this one. Any help\direction would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论