- 博客(10)
- 资源 (1)
- 收藏
- 关注
原创 装饰器实现单例模式
使用装饰器实现单例程模式def singleton(cls, *args, **kw): instances = {} def _singleton(): if cls not in instances: instances[cls] = cls(*args, **kw) return instances[cls] r...
2018-06-24 14:15:06 766
原创 打印程序运行时间
用装饰器实现打印程序运行时间import timedef print_run_time(func): def wrapper(*args, **kw): start = time.time() func(*args, **kw) end =time.time() - start print "run time is %s"...
2018-06-24 13:54:48 751
原创 python实现基本算法
1. 冒泡排序本文采用两种方法进行冒泡排序,第一种:第一次排序后,数组中的第一个元素最小def bubble_sort(lists): # 冒泡排序 count = len(lists) for i in range(count): for j in range(i + 1, count): if lists[i] &g...
2018-06-22 21:37:49 239
原创 Golang study
Useful URLhttps://golang.org/https://play.golang.org/https://atom.io/https://github.com/nsf/gocode
2018-06-13 09:11:06 228
原创 subprocess
import subprocess_VERBOSE = Truedef run_cmd(cmd): if _VERBOSE: print cmd process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIP...
2018-06-04 16:08:10 607
原创 contextlib
>>> import contextlib>>> @contextlib.contextmanager... def make_context():... print 'enter'... try:... yield {}... except RuntimeError, err:... pri...
2018-06-04 10:29:00 516
原创 dictionary
>>> a = {"1":"WuWei"}>>> name = a.pop('2', [])>>> name[]>>> name = a.pop('2')Traceback (most recent call last): File "<stdin>&
2018-06-03 19:03:09 186
原创 set and frozenset
>>> x = set("A Python")>>> xset(['A', ' ', 'h', 'o', 'n', 'P', 't', 'y'])Sets are implemented in a way, which doesn't allow mutable objects.>>> name = set((["name1", &
2018-06-03 17:44:08 141
原创 textwrap
dedent it’s the design of textwrap.dedent: On the first line you have to set the ammount of space you want to dedent in the lines below, otherwise it will capture the position of the first text to se...
2018-06-03 09:01:15 203
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人