This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| # Author: Ficapy | |
| # Create: '15/7/31' | |
| # https://docs.python.org/3/faq/programming.html#why-are-default-values-shared-between-objects | |
| import requests | |
| import time |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| # Author: Ficapy | |
| # Create: '15/7/27' | |
| # from __future__ import unicode_literals | |
| # 兼容2和3 | |
| x = '啦啦啦,' | |
| try: | |
| x = unicode(x, 'utf-8') if isinstance(x, str) else x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def foo(f, b): | |
| c = 3 | |
| # 以下写法错误,locals是会变化的即使使用list(locals())依然无法得到正确的结果 | |
| # [locals.get(i) for i in locals()] | |
| # 以下2、3通用 | |
| frame = inspect.currentframe() | |
| args, _, _, value = inspect.getargvalues(frame) | |
| print({i:value.get(i) for i in args}) | |
| foo(1, 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| from bson import ObjectId | |
| a = {'1': ObjectId('53ef2d847f55f618ce13f24')} | |
| def default(o): | |
| """Implement this method in a subclass such that it returns | |
| a serializable object for ``o``, or calls the base implementation | |
| (to raise a ``TypeError``). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ubuntu install lxml requires | |
| sudo apt-get install libxml2-dev libxslt-dev python-dev lib32z1-dev | |
| # 在digitalocean 512M内存机器上报错,升级到1G内存正常 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Use Gists to store code you would like to remember later on | |
| console.log(window); // log the "window" object to the console |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| # Author: Ficapy | |
| # Create: '15/5/7' | |
| #没人比我更蛋疼了吧 | |
| a = [1,2,3,2] | |
| from itertools import permutations | |
| llist = len(a) | |
| x = [((n+1)/(llist-1) if not (n+1)%(llist-1) else (n+1)/(llist-1)+1,n+1) for n,i in enumerate(permutations(a,2)) if i[0]==i[1]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from functools import partial | |
| import math | |
| remove = lambda x, comp: not (x > comp and not x % comp) | |
| def primerlist(n): | |
| assert isinstance(n, int) | |
| assert n >= 4 | |
| arr = range(2, n + 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # coding:utf-8 | |
| import logging | |
| import requests | |
| import json | |
| _session = requests.Session() | |
| # APT KEY |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| wget "https://bootstrap.pypa.io/get-pip.py" | |
| python get-pip.py | |
| sudo apt-get build-dep -y python-lxml (#该步骤会下载一百多M的依赖包安装) | |
| pip install pyquery | |
| 亦或者直接安装python-lxml包 | |
| 如果你不需要将pyquery安装到虚拟环境中,那么直接安装python-pyquery包是最简单的~~~ | |
| 用上面的办法实在是因为各种测试网上类似的 | |
| sudo apt-get install libxml2-dev libxslt1-dev python-dev zlib1g-dev #诸如此类不给力才有此下策 |