|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
文中我已经将target.truncate()注释掉了,但运行起powershell一点影响也没有,这是为什么,难道这句话没用吗?
from sys import argv
script,filename=argv
print"we're going to erase %r." %filename
print"if you don't want that,hit CTPL-C(^C)."
print"if you do want that,hit RETURN."
raw_input("?")
print"opening the file..."
target=open(filename,'w')#以写模式 打开test.txt
print"truncating the file.Goodbay!"
#target.truncate()#清空text.txt文件
print"now i'm going to ask you for three lines."
line1=raw_input("line 1:")#输入1,2,3行内容
line2=raw_input("line 2:")
line3=raw_input("line 3:")
print"i'm going to write these to the file."
target.write(line1) #写入1,2,,3行内容
target.write("\n") #target.write(line1+"\n"+line2+"\n"+line3)
target.write(line2)
target.write("\n")
target.write(line3)
target.write("\n")
print"and finally,we close it."
target.close()#关闭文本,并保存
也可以说没用吧。因为你用W模式打开文件,所以文件每次都会覆盖写,跟清空的效果是一样的
|
|