上一页 1 ··· 8 9 10 11 12 13 14 15 下一页
摘要: 一:编写函数,(函数执行的时间用time.sleep(n)模拟) import timedef index(a, b): num = a + b time.sleep(6) print(num) return num 二:编写装饰器,为函数加上统计时间的功能 def timer(func): def 阅读全文
posted @ 2020-03-23 18:32 凌醉枫 阅读(180) 评论(0) 推荐(0) 编辑
摘要: 无参装饰器 一:储备知识 1、 *args, **kwargsdef index(x,y): print(x,y)def wrapper(*args,**kwargs): index(*args,**kwargs) # index(y=222,x=111)wrapper(y=222,x=111) 2 阅读全文
posted @ 2020-03-23 17:27 凌醉枫 阅读(217) 评论(0) 推荐(0) 编辑
摘要: 函数对象 # 精髓:可以把函数当成变量去用# func=内存地址def func(): print('from func') 1、可以赋值f=funcprint(f,func)f() 2、可以当做函数当做参数传给另外一个函数 def foo(x): # x = func的内存地址 print(x)x 阅读全文
posted @ 2020-03-20 18:06 凌醉枫 阅读(244) 评论(0) 推荐(0) 编辑
摘要: 1.函数对象优化多分支if的代码练熟 def login(): print("登录功能")def register(): print("注册功能")func_dic = { '1': ('登录', login), '2': ('注册', register), '0': ('退出', None)}de 阅读全文
posted @ 2020-03-20 17:32 凌醉枫 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 要求:下述所有代码画图以及分析代码执行流程1、以定义阶段为准,先画出名称空间的嵌套关系图 2、然后找到调用函数的位置,写出函数调用时代码的执行过程,涉及到名字的查找时,参照1中画好的嵌套图,标明查找顺序,一层一层直到找到位置 # 题目一 input=333def func(): input=444f 阅读全文
posted @ 2020-03-19 19:42 凌醉枫 阅读(172) 评论(0) 推荐(0) 编辑
摘要: 昨日review 0: 引用传递 python中所有值的传递,传递的都是不是值本身,而是值的引用,即内存地址 1、函数分为两大类,分别是是什么?二者在使用时有何区别? 内置函数 自定义函数 2、什么是形参、什么是实参?形参与实参之间的关系是什么? def func(x,y): print(x) fu 阅读全文
posted @ 2020-03-19 17:34 凌醉枫 阅读(215) 评论(0) 推荐(0) 编辑
摘要: 1、写函数,,用户传入修改的文件名,与要修改的内容,执行函数,完成批了修改操作 def modify_file(filename,old,new): import os with open(filename,'r',encoding='utf-8') as read_f,\ open('.bak.s 阅读全文
posted @ 2020-03-18 19:08 凌醉枫 阅读(112) 评论(0) 推荐(0) 编辑
摘要: Python os模块 os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname") 改变当前脚本工作目录;相当于shell下cd os.curdir 返回当前目录: ('.') 1 os.pardir 获取当前目录的父目录字符串名:('.. 阅读全文
posted @ 2020-03-18 18:20 凌醉枫 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 昨日review: 1、编写代码实现功能tail -f access.log f.seek() 应用程序(文件对象/文件句柄1) 应用程序(文件对象/文件句柄2) 操作系统(真正的文件)a.txt z 计算机硬件(硬盘空间) 2、代码展示文件修改的两种方式 方式一: with open('源文件', 阅读全文
posted @ 2020-03-18 17:56 凌醉枫 阅读(396) 评论(0) 推荐(0) 编辑
摘要: 1、编写文件修改功能,调用函数时,传入三个参数(修改的文件路径,要修改的内容,修改后的内容)既可完成文件的修改 def file(filename, old, new): import os with open(filename, 'r', encoding='utf-8') as read_f,\ 阅读全文
posted @ 2020-03-17 18:55 凌醉枫 阅读(209) 评论(0) 推荐(0) 编辑
上一页 1 ··· 8 9 10 11 12 13 14 15 下一页