摘要: # attr可以简单理解为namedtuple的增强版 import attr @attr.s class Point(object): x = attr.ib(default=1) # 定义默认参数 y = attr.ib(kw_only=True) # 关键字参数 p1 = Point(1, y 阅读全文
posted @ 2021-11-22 15:52 我在路上回头看 阅读(566) 评论(0) 推荐(0) 编辑
摘要: # 示例 import fcntl with open('./test.txt', 'w') as f: fcntl.flock(f, fcntl.LOCK_EX) # 对文件加锁,除加锁进程外其它进程没有对已加锁文件读写访问权限 # fcntl.flock(f, fcntl.LOCK_UN) # 阅读全文
posted @ 2021-11-22 15:51 我在路上回头看 阅读(569) 评论(0) 推荐(0) 编辑
摘要: from string import Template s = Template('$who 在 $do') ts = s.substitute(who="张三", do="赏花") print(ts) # 模板s中默认以$标识需要替换的变量,在substitute以键值对的格式定义替换变量的值,并 阅读全文
posted @ 2021-11-22 15:51 我在路上回头看 阅读(287) 评论(0) 推荐(0) 编辑
摘要: 枚举是与多个唯一常量值绑定的一组符号(即成员)。枚举中的成员可以进行身份比较,并且枚举自身也可迭代。 枚举成员名称建议使用大写字母 # 示例 from enum import Enum,unique, IntEnum(支持成员比较) @unique # unique装饰器确保属性名和值唯一 clas 阅读全文
posted @ 2021-11-22 15:50 我在路上回头看 阅读(254) 评论(0) 推荐(0) 编辑