摘要: import sysimport shutilprint(sys.argv)#命令行参数list,第一个元素是程序本身路径# print(sys.exit(n))#退出程序,正常退出exit(0)print(sys.version)#获取python版本解释器信息print(sys.maxint)# 阅读全文
posted @ 2020-06-10 07:55 安好_世界 阅读(69) 评论(0) 推荐(0) 编辑
摘要: import osprint(os.getcwd())#获取当前目录,即当前python脚本工作的路径print(os.chdir(r'D:\tool\python3.7.6\a13'))#改变当前脚本工作目录,相当shell中的cdprint(os.getcwd())#获取当前目录print(os 阅读全文
posted @ 2020-06-09 22:01 安好_世界 阅读(170) 评论(0) 推荐(0) 编辑
摘要: import random# print(random.randint(1,3))#取1-3的值,包括1和3# random.randrange(1,3)#不包含3# random.choice('')#放入序列,后面可以设置字符长度# random.uniform(1,3)#取浮点数# rando 阅读全文
posted @ 2020-06-08 07:50 安好_世界 阅读(106) 评论(0) 推荐(0) 编辑
摘要: import time,datetime# time.timezone()#获取时区,显示为秒# time.sleep()#休眠# time.gmtime()#需要传个时间戳,不传就是UTC市区标准时间# time.localtime()#获取的本地时间# time.mktime()#传入元组模式, 阅读全文
posted @ 2020-06-08 07:26 安好_世界 阅读(150) 评论(0) 推荐(0) 编辑
摘要: import i#执行logger()方法,i.logger()执行from i import * #把a所有的代码都复制过来,直接logger()执行from i import a as test #别命名为test#import 本质是把文件解释一遍,同时赋值给i变量#from i import 阅读全文
posted @ 2020-06-04 21:23 安好_世界 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 1. __doc__ 表示类的描述信息 2. __module__ 和 __class__ __module__ 表示当前操作的对象在那个模块 __class__ 表示当前操作的对象的类是什么 3. __init__ 构造方法,通过类创建对象时,自动触发执行。 4.__del__ 析构方法,当对象在 阅读全文
posted @ 2020-06-02 17:37 安好_世界 阅读(224) 评论(0) 推荐(0) 编辑
摘要: import json,picklejson.dumps()#序列化,字典转换成字符串,只dumps一次json.loads()#反序列化,字符串转换字典pickle.dumps()#序列化,转换成2进制pickle.loads()pickle.dump(info,f)#完全相等f.write(pi 阅读全文
posted @ 2020-05-29 07:33 安好_世界 阅读(161) 评论(0) 推荐(0) 编辑
摘要: #abs() 函数返回 x(数字)的绝对值,如果参数是一个复数,则返回它的大小。# all()#函数用于判断给定的可迭代参数 iterable 中的所有元素是否都为 TRUE,如果是返回 True,否则返回 False。# 元素除了是 0、空、None、False 外都算 True。# any()# 阅读全文
posted @ 2020-05-27 07:49 安好_世界 阅读(140) 评论(0) 推荐(0) 编辑
摘要: import timedef consumer(name): print("%s 准备吃包子啦!" % name) while True: baozi = yield print("包子[%s]来了,被[%s]吃了!" % (baozi, name))c = consumer('LiuCheng') 阅读全文
posted @ 2020-05-26 07:23 安好_世界 阅读(176) 评论(0) 推荐(0) 编辑
摘要: 装饰器: 定义:本质是函数,(装饰其他函数)就是为其他函数添加附加功能 原则:1.不能修改被装饰的函数的源代码 2.不能修改被装饰的函数的调用方式 import time #嵌套函数def foo(): print('in the foo') def bar(): print('in the bar 阅读全文
posted @ 2020-05-24 21:07 安好_世界 阅读(143) 评论(0) 推荐(0) 编辑