最简单的方式离线部署Python依赖包
摘要:最简单的方式离线部署Python依赖包 SHOW ME CODE! 打包: $ tempdir=$(mktemp d /tmp/wheelhouse XXXXX) $ pip wheel r requirements.txt wheel dir=$tempdir $ cwd= $ (cd "$tem
阅读全文
posted @
2017-10-05 14:26
eshizhan
阅读(2254)
推荐(0)
Mock an function to modify partial return value by special arguments on Python
摘要:Mock an function to modify partial return value by special arguments on Python python mock一个带参数的方法,修改指定参数的返回值,大家直接看代码就能懂。 want mock code: mock code:
阅读全文
posted @
2017-10-05 14:02
eshizhan
阅读(388)
推荐(0)
Debian/Ubuntu pip default install to $HOME/.local
摘要:pip default install to $HOME/.local on Debian/Ubuntu After pip 8.1.1 2 on Debian or Ubuntu you can pip install package without root user, which defaul
阅读全文
posted @
2017-10-05 11:51
eshizhan
阅读(426)
推荐(0)
python requests 配置超时及重试次数
摘要:import requestsfrom requests.adapters import HTTPAdapters = requests.Session()s.mount('http://', HTTPAdapter(max_retries=3))s.mount('https://', HTTPAd...
阅读全文
posted @
2015-12-24 12:05
eshizhan
阅读(23139)
推荐(2)
Python技巧之list去重与dict排序
摘要:都是PEP上找到的:list列表去重复项list(set(l))dict字典排序from operator import itemgettersorted(d.iteritems(), key=itemgetter(1), reverse=True)
阅读全文
posted @
2013-01-25 11:42
eshizhan
阅读(2708)
推荐(0)
Python URL Shortening(Python短地址)
摘要:唉,有好久没写blog了。——非著名程序员今天讨论URL shortening,即短地址,顾名思义把URL变短,服务器通过查询短地址,提供302跳转到目的地址。长短地址之间映射的方法有很多,我查到大概两类:MD5抽样,唯一ID+BASE62。我选择了后者,至于为什么?也许有很多理由,也许没有理由。Python有现成类库两枚,short_url (不带DB,只有ID<->base62,有生成最小位数参数,DB自选,一般选择NoSQL),另一个是shorten (可存储到redis或Memory)。另外还可以通过第三方提供的短地址服务,这个就多了吧,很多都提供免费API,自己Googl
阅读全文
posted @
2013-01-17 22:10
eshizhan
阅读(1434)
推荐(0)
质数
摘要:数学,永远是那么神奇!1.质数是其中一个永久的话题,今天在stackoverflow上又看到一奇贴,分享之。是关于Python生成质数的,有兴趣研究的,请做好长时间Google的准备。http://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python2.RSA算法也离不开质数,而且是大质数,其实Linux下的openssl可以通过命令行验证和生成大质数。$ openssl prime 1313 is prime$ openssl prime -generate -bits 102
阅读全文
posted @
2012-10-05 23:08
eshizhan
阅读(543)
推荐(0)
ImportError: No module named qtdemo_rc
摘要:python-qt4-doc/examples problemQ:"ImportError: No module named qtdemo_rc" when running pyqt demo.A:pyrcc4 -o qtdemo_rc.py qtdemo.qrcTips:#!/usr/bin/env python2# -*- coding: utf-8 -*-import osimport sysif len(sys.argv) > 1: pth = sys.argv[1]else: pth = '.'for root, dirs, files in
阅读全文
posted @
2012-09-27 17:42
eshizhan
阅读(600)
推荐(0)
Replace multiple spaces with one space in Python(替换多个空格为一个空格)
摘要:s=" a b c "" ".join(s.split())awesome python!
阅读全文
posted @
2011-12-29 17:55
eshizhan
阅读(2739)
推荐(0)
The easy way to execute sudo command in Python using subprocess.Popen
摘要:run a command as root using sudo from Python: 1 import subprocess 2 3 def mypass(): 4 mypass = '123' #or get the password from anywhere 5 return mypass 6 7 echo = subprocess.Popen(['echo',mypass()], 8 stdout=subprocess.PIPE, 9 )10 11 sudo = ...
阅读全文
posted @
2011-12-29 09:59
eshizhan
阅读(3430)
推荐(1)