函数运行时间
import time
import functools
from functools import singledispatch
def clock(func):
@functools.wraps(func)
def clocked(*args, **kwargs):
t0 = time.time()
################## install oh-my-zsh ####################### | |
sudo apt-get install git | |
sudo apt-get install zsh | |
wget --no-check-certificate http://install.ohmyz.sh -O - | sh | |
这时可能会出现 密码: chsh:PAM, 手动输入 chsh -s /bin/zsh 即可解决 | |
注销或重启就ok了 |
./bin/md2resume html examples/source/sample.md examples/output/ | |
./bin/md2resume pdf examples/source/sample.md examples/output/ | |
# Choose a template with the -t option. | |
./bin/md2resume html --template blockish examples/source/sample.md examples/output/ | |
# If you want to edit your markdown resume in your editor while watching it update in your browser, run this command: |
## 2.8 用bisect来管理已排序的序列 | |
import bisect | |
import sys | |
Haystack = [1, 4, 5, 6, 8 ,12, 15, 20, 21, 23, 23, 26, 29, 30] # 干草垛 | |
Needles = [0, 1, 2, 5, 8, 10, 22, 23, 29, 30, 31] # 针 | |
ROW_FMT = '{0:2d} @ {1:2d} {2}{0:<2d}' |
import collections | |
class StrKeyDict0(dict): # 继承dict | |
def __missing__(self, key): | |
if isinstance(key, str): # 找不到的键是字符串,抛出keyerror异常 | |
raise KeyError(key) | |
return self[str(key)] # 找不到的键转为字符串再查找 | |
def get(self, key, default=None): | |
try: |
# 6.使用一等函数实现设计模式 | |
from collections import namedtuple | |
Customer = namedtuple('Customer', 'name fidelity') | |
class LineItem(object): | |
def __init__(self, product, quantity, price): | |
self.product = product | |
self.quantity = quantity | |
self.price = price |
# 7 函数装饰器和闭包 | |
## 使用装饰器改进策略模式 | |
from collections import namedtuple | |
Customer = namedtuple('Customer', 'name fidelity') | |
class LineItem(object): | |
def __init__(self, product, quantity, price): |
函数运行时间
import time
import functools
from functools import singledispatch
def clock(func):
@functools.wraps(func)
def clocked(*args, **kwargs):
t0 = time.time()
普通多线程:
def __init__(self, name_2_id_path, triple_path):
self.name_2_id_path = name_2_id_path
self.triple_path = triple_path
self.entity_2_id_set = defaultdict(dict)
self.triple_set = defaultdict(dict)
t1 = Thread(target=self.load_name_2_id)
直接多进程
class KnowledgeEngine:
def __init__(self, name_2_id_path, triple_path):
self.name_2_id_path = name_2_id_path
self.triple_path = triple_path
self.entity_2_id_set = defaultdict(dict)
self.triple_set = defaultdict(dict)
t1 = Thread(target=self.load_name_2_id)
### 基础的singledispatch装饰器只能实现静态方法 | |
from functools import singledispatch | |
class TestClass(object): | |
@singledispatch | |
def test_method(arg, verbose=False): | |
if verbose: | |
print("Let me just say,", end=" ") |