【问题标题】:How can I add text to a text file using Bash or Python [duplicate]如何使用 Bash 或 Python 将文本添加到文本文件 [重复]
【发布时间】:2015-10-27 12:04:34
【问题描述】:

我有一个大文件,每行有 4 个数字。现在我希望在每个数字之前添加 8 个零。如何在 Bash 或 Python 中做到这一点?

【问题讨论】:

    标签: python bash


    【解决方案1】:

    这应该可行:

    myfile = open("filename.txt")
    items = myfile.read().split("\n")
    mystr = ""
    for x in range(0, len(items)):
        mystr += "00000000" + items[x] + "\n"
    myfile = open("filename.txt", 'w')
    myfile.write(mystr)
    myfile.close()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-24
      • 1970-01-01
      • 1970-01-01
      • 2012-10-22
      • 2016-03-25
      • 1970-01-01
      • 1970-01-01
      • 2021-06-04
      相关资源
      最近更新 更多