python小工具---旋转的等待符

python小工具–无聊等待旋转符

有时候在等待交互的时候很无聊,就搞了一个小符号,只需要给函数加上这个deco装饰器即可,做点小记录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# -*-coding: utf-8-*-
'''
Created Time: 二 7/26 09:26:56 2016
mail: liangyou.qiao@shuyun.com
Author: liangyou.qiao
File Name: funny.py
'''
import sys
import time
spinners = '''|/-\\'''
spinpos = 0
def fwrite(buf):
sys.stdout.write(buf)
sys.stdout.flush()
def spin():
global spinpos
fwrite(spinners[spinpos]+"\b")
spinpos += 1
if spinpos >= len(spinners):
spinpos = 0
def funny()
while 1:
spin()

使用装饰器

1
2
3
4
5
6
7
8
9
10
11
import functools
def deco(func):
@functools.wraps(func)
def wrapper(*a,**kw):
print "进入等待"
spin()
result = func(*a,**kw)
return result
return wrapper