-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyprint.py
56 lines (44 loc) · 1.37 KB
/
myprint.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
"""
Created on Fri May 19 18:40:44 2017
@author: Christoph Stenkamp
"""
#10 is highest, 1 is lowest, 5 prints everything not specified
from collections import deque
PRINTLEVEL = 5
MAX_NORMAL_LEVEL = 10
ONLYONCELEVEL = -1
#nicht auf 10 reduzieren, sondern sobald mal einer mit über 10 kam, printet er von da an nur noch den
onceprintedobjects = deque(100*[None], 100)
def myprint(*args, **kwargs):
global PRINTLEVEL
try:
level = kwargs["level"]
if level > MAX_NORMAL_LEVEL:
PRINTLEVEL = level
except KeyError:
level = 5
if level == ONLYONCELEVEL:
if not args in onceprintedobjects:
onceprintedobjects.append(args)
level = PRINTLEVEL
if level >= PRINTLEVEL:
print(*args)
def printtofile(*args, **kwargs):
global PRINTLEVEL
try:
level = kwargs["level"]
if level > MAX_NORMAL_LEVEL:
PRINTLEVEL = level
except KeyError:
level = 5
if level == ONLYONCELEVEL:
if not args in onceprintedobjects:
onceprintedobjects.append(args)
level = PRINTLEVEL
if level >= PRINTLEVEL:
with open("log.txt", "a") as myfile:
args = [str(i) for i in args]
text = " ".join(args)
print(text)
myfile.write(text+"\n")