Python学习日记 09

今天是学习的第九天。
正值国庆期间,聚会也开始多了起来。

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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 《六项精进》打卡第27天 姓名:王燕君 公司.:宁波万尚进出口公司 组别:364期利他3组 【知~学习】 诵读活法...
    王燕君分水碶阅读 77评论 0 0
  • 真的是服了这个老板,放假前说好的的明天上班,但是昨天下午在群里说让今天上班,今天就傻傻的做一天吧!提前上班起码提前...
    望飞雪阅读 166评论 3 1
  • 唏哩哗啦的春雨伴奏着夜的旋律。沉沉的睡眠中,乱梦无数。但其中一个梦在不同时间的梦里面,反复的出现,被深刻的记住了。...
    晓枫晨露阅读 536评论 2 1