03 2020 档案

摘要:# 作业: # 1、把登录与注册的密码都换成密文形式 import hashlib def registered(): name=input('请输入您想注册的用户名:').strip() pwd=input('请输入您想注册的登录密码:').strip() c_pwd=input('请再次输入您的 阅读全文
posted @ 2020-03-31 21:48 It's_cool 阅读(105) 评论(0) 推荐(0)
摘要:常用模块2 json&pickle模块 什么是序列化? 我们把对象(变量)从内存中变成可存储或传输的过程称之为序列化,在Python中叫pickling,在其他语言中也被称之为serialization,marshalling,flattening等等,都是一个意思。 内存中的数据类型 >序列化 > 阅读全文
posted @ 2020-03-31 17:35 It's_cool 阅读(200) 评论(0) 推荐(0)
摘要:# 今日作业: # 1、检索文件夹大小的程序,要求执行方式如下 # python3.8 run.py 文件夹 import os x=r'D:\222' def func(i): l=os.listdir(i) for z in l: if os.path.isdir(f'{x}\{z}'): pr 阅读全文
posted @ 2020-03-31 00:55 It's_cool 阅读(134) 评论(0) 推荐(0)
摘要:常用模块 time与datetime模块 一、time 时间戳:表示的是从1970年1月1日00:00:00开始按秒计算的偏移量,返回的是float类型。 作用:用于时间间隔的计算 import time print(time.time()) #1585552747.5992923 按照某种格式显示 阅读全文
posted @ 2020-03-30 15:49 It's_cool
摘要:python文件的两种用途 1、被当成程序运行2、被当做模块导入 如何区别二者的用途? 当一个python文件 被运行时,__name__的值为'__main__' 当一个python文件 被当做模块导入时,__name__的值为那个模块的文件名 from-import from...import. 阅读全文
posted @ 2020-03-27 23:24 It's_cool 阅读(193) 评论(0) 推荐(0)
摘要:# 作业: # 1、文件内容如下,标题为:姓名,性别,年纪,薪资 # egon male 18 3000 # alex male 38 30000 # wupeiqi female 28 20000 # yuanhao female 28 10000 # 要求: # 从文件中取出每一条记录放入列表中 阅读全文
posted @ 2020-03-27 00:05 It's_cool 阅读(103) 评论(0) 推荐(0)
摘要:算法之二分法 算法:是高效解决问题的办法 需求:有一个按照从小到大顺序排列的数字列表 需要从该数字列表中找到我们想要的那个一个数字 如何做更高效??? 方案一:整体遍历# 效率太低 nums=[-3,4,13,10,-2,7,89] nums.sort() # .sort 排序 find_num=1 阅读全文
posted @ 2020-03-26 16:26 It's_cool 阅读(130) 评论(0) 推荐(0)
摘要:# 1、文件内容如下,标题为:姓名,性别,年纪,薪资 # egon male 18 3000 # alex male 38 30000 # wupeiqi female 28 20000 # yuanhao female 28 10000 # # 要求: # 从文件中取出每一条记录放入列表中, # 阅读全文
posted @ 2020-03-25 22:11 It's_cool 阅读(107) 评论(0) 推荐(0)
摘要:叠加多个装饰器 加载顺序自下而上 执行顺序自上而下 def deco1(func1): # func1 = wrapper2的内存地址 def wrapper1(*args,**kwargs): print('正在运行 >deco1.wrapper1') res1=func1(*args,**kwa 阅读全文
posted @ 2020-03-25 17:45 It's_cool 阅读(110) 评论(0) 推荐(0)
摘要:# 作业: # 1、编写课上讲解的有参装饰器准备明天默写 def auth(db_type): def deco(func): def wrapper(*args, **kwargs): name = input('your name>>>: ').strip() pwd = input('your 阅读全文
posted @ 2020-03-25 00:04 It's_cool 阅读(199) 评论(0) 推荐(0)
摘要:装饰器 有参装饰器 以下举例 # 因为deco 与 wrapper都受限制 所以wrapper里需要新的参数时 就在deco外在包了一层函数 这时候有有参装饰器就形成了 def auth(db_type): # 不受限制 因为deco 与 wrapper都 受限制 所以wrapper里需要新的参数时 阅读全文
posted @ 2020-03-24 18:00 It's_cool 阅读(156) 评论(0) 推荐(0)
摘要:装饰器 ****** 超级无敌重点 1、什么是装饰器 器指的是工具,可以定义成成函数 装饰指的是为其他事物添加额外的东西点缀 合到一起的解释: 装饰器指的定义一个函数,该函数是用来为其他函数添加额外的功能 2、为何要用装饰器 开放封闭原则 开放:指的是对拓展功能是开放的 封闭:指的是对修改源代码是封 阅读全文
posted @ 2020-03-23 17:41 It's_cool 阅读(221) 评论(0) 推荐(0)
摘要:# 编写ATM程序 # a)登录功能(3 # 分) def login(): dic={} with open(r'D:\cool\user',mode='rt',encoding='utf-8')as x: for y in x: name,pwd,money=y.strip().split(': 阅读全文
posted @ 2020-03-21 23:55 It's_cool 阅读(103) 评论(0) 推荐(0)
摘要:函数对象 精髓:可以把函数当成变量去用 # func=内存地址 def func(): print('from func') 1、可以赋值 def func(): print('from func') f=func f() #from func 2、可以当做函数当做参数传给另外一个函数 def fu 阅读全文
posted @ 2020-03-20 17:46 It's_cool 阅读(126) 评论(0) 推荐(0)
摘要:# 题目一 input=333 def func(): input=444 func() print(input) # print(input)当前是在全局名称空间里 就先在全局名称空间找 发现了input=333 # # 题目二 def func(): print(x) x=111 func() 阅读全文
posted @ 2020-03-19 21:50 It's_cool 阅读(163) 评论(0) 推荐(0)
摘要:命名关键字参数 命名关键字参数:在定义函数时,*后定义的参数,称之为命名关键字参数 特点:命名关键字实参必须按照key=value的形式为其传值 #示范1 def func(x,y,*,a,b): # 其中,a和b称之为命名关键字参数 print(x,y) print(a,b) func(1,2,b 阅读全文
posted @ 2020-03-19 16:02 It's_cool 阅读(177) 评论(0) 推荐(0)
摘要:# 1、写函数,,用户传入修改的文件名,与要修改的内容,执行函数,完成批了修改操作 def file_change(path,file,c_file): with open(path,mode='rb')as f: x=f.read().decode('utf-8').replace(file,c_ 阅读全文
posted @ 2020-03-18 23:56 It's_cool 阅读(172) 评论(0) 推荐(0)
摘要:函数的参数 一 形参与实参介绍 形参:在定义函数阶段定义的参数称之为形式参数,简称形参,相当于变量名 def func(x, y): print(x, y) 实参:在调用函数阶段传入的值称之为实际参数,简称实参,相当于变量值 func(1,2) #形式一: func(1,2) #形式二: a=1 b 阅读全文
posted @ 2020-03-18 17:22 It's_cool 阅读(149) 评论(0) 推荐(0)
摘要:# 1、编写文件修改功能,调用函数时,传入三个参数(修改的文件路径,要修改的内容,修改后的内容)既可完成文件的修改 def file_change(path,file,c_file): with open(path,mode='rb')as f: x=f.read().replace(file,c_ 阅读全文
posted @ 2020-03-17 21:45 It's_cool 阅读(151) 评论(0) 推荐(0)
摘要:文件处理3 .seek 的应用 access.log(访问日志) import time with open(r'D:\cool\access.log', mode='rb') as f: # 1、将指针跳到文件末尾 f.seek(0,2) while True: line=f.readline() 阅读全文
posted @ 2020-03-17 16:24 It's_cool 阅读(195) 评论(0) 推荐(0)
摘要:#1、通用文件copy工具实现 file=input('原文件路径:') c_file=input('目标文件文件路径:') with open(r'{}'.format(file),mode='rb')as x,\ open(r'{}'.format(c_file),mode='wb')as y: 阅读全文
posted @ 2020-03-17 00:12 It's_cool 阅读(120) 评论(0) 推荐(0)
摘要:文件处理2 控制文件操作的模式 补充:x模式 x模式 :只写模式【不可读;不存在则创建,存在则报错】 #了解 #当 文件(D:\cool\user)时 with open(r'D:\cool\user',mode='xt',encoding='utf-8') as f: pass #报错 # 当 文 阅读全文
posted @ 2020-03-17 00:09 It's_cool 阅读(117) 评论(0) 推荐(0)