-
Notifications
You must be signed in to change notification settings - Fork 8
/
tools.py
30 lines (27 loc) · 938 Bytes
/
tools.py
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
30
import os
import sys
import time
from platform import python_implementation
# 计算函数运行时间的
def caculate_time(func):
def wrapper(*args, **kwargs):
start_time = time.time()
func(*args, **kwargs)
end_time = time.time()
print("函数运行时间为:%s" % (end_time - start_time))
return wrapper
# 检测python解释器
def detect_python_interpreter():
try:
from platform import python_implementation
except ImportError: # pragma: no cover
def python_implementation():
"""Return a string identifying the Python implementation."""
if 'PyPy' in sys.version:
return 'PyPy'
if os.name == 'java':
return 'Jython'
if sys.version.startswith('IronPython'):
return 'IronPython'
return 'CPython'
return python_implementation()