gpt4 book ai didi

Python删除行之间的输入/空格

转载 作者:太空宇宙 更新时间:2023-11-04 07:02:47 29 4
gpt4 key购买 nike

好吧,我已经阅读了很多建议如何消除多余空间的帖子,但无论出于何种原因,我似乎无法将这些建议应用到我的系统中,所以我在这里寻求您的帮助。

这些是我代码的最后几行:

    for line in rline[start+5 : end] :
words = line.split()
word1 = int(words[1])
print >>opennew, "%s%s" % (word1,line[30:])

新的“opennew”文件看起来像这样:

    1        0.876153    0.152889   -0.047464

2 1.011880 -1.161641 -2.096289

3 0.883419 1.558736 1.966913

4 2.010367 -1.140725 1.053368

虽然我真正想要的是:

    1        0.876153    0.152889   -0.047464
2 1.011880 -1.161641 -2.096289
3 0.883419 1.558736 1.966913
4 2.010367 -1.140725 1.053368

我是否在代码中添加了一些东西来从我的输入中删除额外的(不需要的)输入/空格?

非常感谢您的帮助。

附言:(请不要问我为什么在代码中拆分行,这是有目的的,这将在将来(更好的)代码中应用)

最佳答案

尝试从 line 中去除换行符:

line = line.rstrip("\n")

关于Python删除行之间的输入/空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13374682/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com