本文主要是介绍笨办法学python 习题16,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
from sys import argv
script,filename = argv
print(f"We're going to erase {filename}.")#删除文件
print("If you don't want that,hit CTRL-C(^C).")
print("If you do want that,hit RETURN.")
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 = input("line 1: ")
line2 = input("line 2: ")
line3 = input("line 3: ")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")print("And finally,we close it.")
target.close()
运行结果
文本文件
参考链接
https://blog.csdn.net/YxWang12/article/details/77203365
这篇关于笨办法学python 习题16的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!