【发布时间】:2015-10-27 12:04:34
【问题描述】:
我有一个大文件,每行有 4 个数字。现在我希望在每个数字之前添加 8 个零。如何在 Bash 或 Python 中做到这一点?
【问题讨论】:
我有一个大文件,每行有 4 个数字。现在我希望在每个数字之前添加 8 个零。如何在 Bash 或 Python 中做到这一点?
【问题讨论】:
这应该可行:
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()
【讨论】: