鱼C论坛

 找回密码
 立即注册
查看: 837|回复: 1

[已解决]笨方法学python16中遇到的疑问?

[复制链接]
发表于 2018-6-22 18:08:24 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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()#关闭文本,并保存
最佳答案
2018-6-22 18:41:27
也可以说没用吧。因为你用W模式打开文件,所以文件每次都会覆盖写,跟清空的效果是一样的
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-6-22 18:41:27 | 显示全部楼层    本楼为最佳答案   
也可以说没用吧。因为你用W模式打开文件,所以文件每次都会覆盖写,跟清空的效果是一样的
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-18 07:43

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表