随笔分类 -  Python进阶

摘要:向处于CLOSE_WAIT的socket发送数据是OK的, 向CLOSED状态的socket发数据触发,BrokenPipeError, 此时fd没有被释放,client此socket没有close, 调用close后, lsof显示连接被释放, 在调用send时, 报OSError 阅读全文
posted @ 2022-10-16 20:29 ascertain 阅读(29) 评论(0) 推荐(0) 编辑
摘要:groupby: import typing, operator, itertools class GroupBy: def __init__(self, iterable: typing.Iterable, key=None): if key is None: key = lambda v: v 阅读全文
posted @ 2022-10-10 13:41 ascertain 阅读(35) 评论(0) 推荐(0) 编辑
摘要:__slots__ 定义为类属性, 约束实例属性, 类定义__slots__后, 实例就没有__dict__ 子类和父类都定义__slots__后, 子类可有全部__slots__属性 父类存在__slots__,子类没有定义__slots__时, 子类存在__dict__ 定义__slots__后 阅读全文
posted @ 2022-09-19 14:08 ascertain 阅读(17) 评论(0) 推荐(0) 编辑
摘要:super不带任何参数,必须在类中使用, 等价于第一参数为当前类,第二参数为当前函数第一参数(self) super(type) 一个参数时 没什么用, 不能调用任何方法 super(type,type2) requires issubclass(type2,type) 未绑定方法, 以type2的 阅读全文
posted @ 2022-09-16 16:47 ascertain 阅读(16) 评论(0) 推荐(0) 编辑
摘要:class Singleton: __obj = None __initiated = False def __new__(cls, *args, **kwargs): if cls.__obj is None: cls.__obj = super(Singleton, cls).__new__(c 阅读全文
posted @ 2022-09-15 10:45 ascertain 阅读(17) 评论(0) 推荐(0) 编辑
摘要:所有function都有 __get__ 用于实现绑定 __get__ class B: def __init__(self, v): self._v = v def v(self): return self._v def bind(instance, func, name=None): if na 阅读全文
posted @ 2022-09-12 20:26 ascertain 阅读(22) 评论(0) 推荐(0) 编辑
摘要:IO TextIO BinaryIO 阅读全文
posted @ 2022-08-19 17:44 ascertain 阅读(19) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2022-08-14 23:03 ascertain 阅读(71) 评论(0) 推荐(0) 编辑
摘要:一个参数时, 此参数必须是dict key: Unicode ordinals(code point) 或 characters, 字符会被转为Unicode ordinals, 即 key 最终都被转为code point value: Unicode ordinals, strings, Non 阅读全文
posted @ 2022-05-01 12:32 ascertain 阅读(25) 评论(0) 推荐(0) 编辑
摘要:''.join([chr(random.randint(48,122)) for _ in range(55)]) 阅读全文
posted @ 2022-04-11 17:43 ascertain 阅读(34) 评论(0) 推荐(0) 编辑
摘要:Server端设置3s才返回数据 单线程 import requests, random, string, datetime def download(url): print('start') response = requests.get(url) print('complete') lst = 阅读全文
posted @ 2022-03-23 13:00 ascertain 阅读(101) 评论(0) 推荐(0) 编辑
摘要:改造老旧教程案例: asyncio.gather import asyncio async def b(): print(5) await asyncio.sleep(2) print(55) return 5 async def p(): print(4) await asyncio.sleep( 阅读全文
posted @ 2022-03-23 11:35 ascertain 阅读(55) 评论(0) 推荐(0) 编辑
摘要:random() 返回一个介于左闭右开[0.0, 1.0)区间的浮点数 基本方法 random.seed(a=None, version=2)初始化伪随机数生成器。如果未提供a或者a=None,则使用系统时间为种子。如果a是一个整数,则作为种子。 random.getstate()返回一个当前生成器 阅读全文
posted @ 2022-03-05 18:51 ascertain 阅读(168) 评论(0) 推荐(0) 编辑
摘要:tk(toolkit)是用来做图形用户界面(GUI graphical user interface)的工具,与tcl命令结合可以创建和操作GUI的窗口组件,Python里面也有一个叫Tkinter的模块作为Tk GUI的接口。 Tcl/Tk快速入门_最实用的Linux博客-CSDN博客 阅读全文
posted @ 2022-03-04 12:35 ascertain 阅读(440) 评论(0) 推荐(0) 编辑
摘要:with open(file) as f: for line in f: for field in line.split(): print(filed) import re from collections import defaultdict valve = '''51.222.253.18 - 阅读全文
posted @ 2022-03-03 21:02 ascertain 阅读(44) 评论(0) 推荐(0) 编辑
摘要:Named Capturing Groups: Backreferences: \number \1 匹配结果的第一个分组 \g<number> \g<1> 匹配结果的第一个分组, 避免歧义 \g<named_group> \g<valor> 匹配命名分组 valor (?P<valor>expre 阅读全文
posted @ 2022-03-03 10:39 ascertain 阅读(33) 评论(0) 推荐(0) 编辑
摘要:import re from collections import defaultdict regex = re.compile(r'[^\w-]+') valor = defaultdict(lambda: 0) with open(file = 'statistic.txt', mode = ' 阅读全文
posted @ 2022-03-02 23:45 ascertain 阅读(21) 评论(0) 推荐(0) 编辑
摘要:IP -> int import socket ip = '5.5.5.5' def inet_aton(a: str): n = 0 for i, v in enumerate(reversed([int(n) for n in a.split('.')])): n += v << (8 * i) 阅读全文
posted @ 2022-03-02 16:57 ascertain 阅读(42) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2022-03-01 13:51 ascertain 阅读(19) 评论(0) 推荐(0) 编辑
摘要:newline: (windows) Only for text mode 写: newline=None (default) newline='' newline='\n' other Summarize: 写文件时, 全部使用 '\n' , newline=None 替换成 os.linesep 阅读全文
posted @ 2022-03-01 13:29 ascertain 阅读(40) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示