This file contains 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 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 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 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 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 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/8/6' | |
import time | |
import math | |
import requests | |
from concurrent.futures import ThreadPoolExecutor, as_completed | |
from xlrd import open_workbook |
This file contains 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 codecs | |
import re | |
import mmap | |
with codecs.open('a.txt', 'r+', 'utf-8') as f: | |
data = mmap.mmap(f.fileno(), 0) | |
print(re.findall(b'AccountType\=(.*)', data)) |
This file contains 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
class A(object): | |
pass | |
a = A() | |
# 给类添加方法 | |
def baz(self): | |
print('baz') | |
A.baz = baz | |
# ==========或者 |
This file contains 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 random | |
from tt import retrys | |
def g(): | |
pass | |
class A(): | |
def __init__(self): |
This file contains 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
# http://stackoverflow.com/questions/18337407/saving-utf-8-texts-in-json-dumps-as-utf8-not-as-u-escape-sequence | |
print(json.dumps({u'卧槽': u'卧槽'}, indent=4).decode('unicode-escape').encode('utf8')) | |
print(json.dumps({u'卧槽': u'卧槽'}, indent=4, ensure_ascii=False)) |