今天是学习的第九天。
正值国庆期间,聚会也开始多了起来。
ok,我先打一下需要运行的代码。
from sys import argv
from os.path import exists
script,from_file,to_file=argv
print(f"copying from {from_file} to {to_file}")
in_file=open(from_file)
indata=in_file.read()
print(f"the input file is {len(indata)} bytes long")
print("ready,hit return to continue,ctrl_c to abort.")
input()
out_file = open(to_file,'w')
out_file.write(indata)
print("alright,all done")
out_file.close()
in_file.close()
就是这段代码,按照惯例,打出来的时候我还是懵逼的。。。。(这个理解能力也是醉了。。。)
静下心来看看。
写一些注释好了。
from sys import argv
#照例是从sys里面调用argv的方式
from os.path import exists
#类型和上面一样,不过,这两个都没见过。我查下。
#据说,os.path模块主要用于文件的属性获取。
#而exists据说是判断是否存在的语句。
script,from_file,to_file=argv
#这里还是照例,规定了argv的值,这里的file都是你要在temainl里面规定出来的文件夹。
print(f"copying from {from_file} to {to_file}")
#这段打印就不说了
in_file=open(from_file)
#打开被复制的文件夹
indata=in_file.read()
#读取这个文件夹
print(f"the input file is {len(indata)} bytes long")
#这里应该是统计字符
print("ready,hit return to continue,ctrl_c to abort.")
#这里就是选择是不是要继续
input()
#这里是输入
out_file = open(to_file,'w')
#这里是打开复制的文件夹
out_file.write(indata)
#把indata已经读取的文件,写进去
print("alright,all done")
out_file.close()
in_file.close()
#关闭
这个的确,写一遍就知道了大概情况了。
其实这一期就是把之前的结果,复习了一遍。然后运行试试。
一次成功
学到这里,我想了一个计划,等到国庆结束之后,我决定一边学习这本书,一边装一些ide试试手。
毕竟我主要的目的在于学习爬虫。
好了,明天在继续吧。
see you