-
Notifications
You must be signed in to change notification settings - Fork 33
/
tools.py
38 lines (30 loc) · 958 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
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
import sys, os
from time import time
def create_dir(folder):
'''
creates a folder, if necessary
'''
if not os.path.exists(folder):
os.makedirs(folder)
class TimePrint(object):
'''
Simple convenience class to print who long it takes between successive calls to its __init__ function.
Usage example:
TimePrint("some text") -- simply prints "some text"
<do some stuff here>
TimePrint("some other text ") -- prints "some other text (took ?s)", where ? is the time passed since TimePrint("some text") was called
'''
t_last = None
def __init__(self, text):
TimePrint.p(text)
@classmethod
def p(cls, text):
t = time()
print text,
if cls.t_last!=None:
print " (took ", t-cls.t_last, "s)"
cls.t_last = t
sys.stdout.flush()
if __name__=="__main__":
print "this is just a library."