任何人都可以帮助我完成此任务。我是Python的新手。我试图做到这一点: 文件名应该是硬代码名称叫做:Server_Information.txt和第二列应该由用户输入插入,但日期戳。 内置者:李四 构建日期:%d%M%Y 生成原因:游乐场 请求者:李四从用户输入创建文件
也许我可以用这个测试脚本,但第一列不会在最后的测试文件显示。
谢谢你对任何人可以帮助
from sys import argv
script, filename = argv
print "We're going to erase %r." % filename
print "If you don't want that, hit CTRL-C (^C)."
print "If you do want that, hit RETURN."
raw_input("?")
print "Opening the file..."
target = open(filename, 'w')
print "Truncating the file. Goodbye!"
target.truncate()
print "Now I'm going to ask you for three lines."
line1 = raw_input("Built By : ")
line2 = raw_input("Build Date: %d%m%y ")
line3 = raw_input("Build Reason: ")
line4 = raw_input("Requestor: ")
print "I'm going to write these to the file."
target.write(line1)
target.write("\n")
target.write(line2)
target.write("\n")
target.write(line3)
target.write("\n")
target.write(line4)
print "And finally, we close it."
target.close()
同样在这里,我用你的替换我的target.write,不工作给我错误。 – pirulo 2014-10-10 13:40:41