Python读取超大文件 Posted on 2020-09-26 当文件超大的时候,读取数据不能采用直接读的方式,要采用块chunk读取的方式,每次只取一小块。 示例:读取单行 10G 文件并根据分隔符进行分割 1234567891011121314151617181920212223242526def read_bigfile(f, seq): """ ... Read more »
为什么Python不要去继承内部的dict, list等数据结构 Posted on 2020-09-26 因为Python内置的dict、list等数据结构是用C语言实现的,里面一些关键方法不能被覆盖,否则会出问题。 如果要实现自定义的dict或list,去继承collections模块下的 UserDict、UserList、UserString Read more »
JWT详解 Posted on 2020-09-19 JWT 是什么JWT不等价于JWS(JSON Web Signature)、JWE(JSON Web Encryption),JWS和JWE是JWT的实现方式。 JWS 的组成 头部(Header)头部用于描述关于该 JWT 的最基本的信息例如:其类型、以及签名所用的算法等。JSON 内容要经 B ... Read more »
Python获取字符串的unicode Posted on 2020-09-17 Python获取字符串的unicode "xxx".encode('unicode-escape') Read more »
Python的函数原理 Posted on 2020-09-15 Python 的函数原理Python.exe 会调用 C 语言函数PyEval_EvalFrameEx去执行foo函数,首先会创建一个栈帧(stack frame),示例如下: 123456789101112def foo(): bar()def bar(): passif __name ... Read more »
生成器 Posted on 2020-09-14 生成器函数是什么123456789101112131415def gen_func(): yield 1def func(): return 1if __name__ == '__main__': result1 = gen_func() print(result1) ... Read more »
迭代器 Posted on 2020-09-14 迭代器是什么迭代器是访问集合内元素的一种方式,一般用来遍历数据,迭代器和下标访问的方式不同,迭代器不能返回,且迭代器提供了一种惰性方式的数据获取方法 iter()函数可以将iterable变为 iterator __iter__返回一个iterator,如果实现了这个方法,则对象可迭代,如果未实现, ... Read more »
__slots__ Posted on 2020-09-14 经典场景:http://tech.oyster.com/save-ram-with-python-slots/使用了slots让内存占用从 25.5GB 降到了 16.2GB 1234567891011121314151617181920212223242526272829303132333435f ... Read more »
从本地读取cookie Posted on 2020-01-03 从本地读取对应的cookie,用来应付像钉钉这种应用 可以使用Navicat来查看Cookie文件 1234567891011121314151617181920import osimport sqlite3def get_cookie_from_dingtalk(host='.baidu.com' ... Read more »
Ubuntu走局域网代理 Posted on 2019-12-02 Ubuntu use local area network Shadowsocks-Go proxy Devices: Ubuntu 18.04 & Windows 10 set windows shadowsocks client allow other devices to conne ... Read more »