Py学习  »  Python

Python学习日记 08

舍山 • 5 年前 • 460 次点击  

今天是学习的第八天。

准备复习一下,把上一次课的自己写一遍。

from sys import argv

argv = script,filename

print(f"let us open the {filename}")
print("if you want open ,hit ctrl_v")
print("if you donot want this, hit return")
input(?)

print("open the filename...")
target open(filename,'w')

print("clean the file..")
target.truncate()

line1=input(first)
line2=input(second)

target.write(line1)

先对比着写了一次,没运行。
全部删除后,自己重新写一次。

from sys import argv
script,filename=argv

print(f"let us do open this {filename}")
print("if you donnot try this, hit ctrl_v")
print("if you  try this ,hit return")
input(try?)

print(f"let us open this {filename}")
target.open(filename,'w')
target.turruncate()

#开始输入内容
line1=(1234)
line2=(2345)

target.write(line1)
target.write(/n)
target.write(line2)

target.close()

然后,我们运行看看。
果然没有一次成功的,先出了一个问题。


try?

我改成了“?”
继续尝试。

原来是我自己sb了,应该要加“”。

然后,又出问题了


我看看

我对比了下,原来这种语句是需要加“”的。

我改成了这样

继续运行,继续报错


image.png

我很奇怪了,为什么下面可以用.,而上面只能用=
先放下,继续运行。

继续报错。。。崩溃中。。


image.png

输入内容这里忘记了input
于是我改成了这样。


这样

继续运行。终于成功了。
最后的代码是这样的。

from sys import argv
script,filename=argv

print(f"let us do open this {filename}")
print("if you donnot try this, hit ctrl_v")
print("if you  try this ,hit return")
input("try?")

print(f"let us open this {filename}")
target = open(filename,'w')
target.truncate()

#开始输入内容
line1=input("1234")
line2=input("2345")

target.write(line1)
target.write("\n")
target.write(line2)

target.close()

明天继续吧。

see you


今天看啥 - 高品质阅读平台
本文地址:http://www.jintiankansha.me/t/tbQHvYImvt
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/24530
 
460 次点击