任何人都可以幫助我完成此任務。我是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