sudo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple xxx-package
[......]
Category Archives: Python
Leave a reply
使用nuitka将Python文件编译成可执行程序
安装
sudo pip3 install nuitka
编译成可执行程序
python3 -m nuitka --standalone --follow-imports ./test.py
会生成一个test.dist的目录,把整个目录拷贝上去,就可以执行了。
需要说明的是,现在nuitka不支持静态链接,所以如果glibc相关库对不上的话,也是没法执行的,建议安装个同版本的系统(docker即可),去编译下就好。[......]
peewee解决问题"OperationalError: (2006, 'MySQL server has gone away')"
用过MySQL的应该都知道,MySQL默认长链接只能保持8小时,超过后就会自动断开。
在peewee中如何维持长连接呢?
解决方法比较晦涩,需要自定义一个支持重试的mixin,然后自定义一种RetryMySQLDatabase混入mixin
from peewee import *
from peewee import __exception_wrapper__
class RetryOperationalError(object):
def execute[......]
Python如何递归的获取dict中的key
def get_recursively(search_dict, field):
"""
Takes a dict with nested lists and dicts,
and searches all dicts for a key of the field
provided.
"""
fields_found = []
for key, value in search_dict.iteritems():[......]