-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInfinity-Posibility.py
More file actions
166 lines (150 loc) · 4.41 KB
/
Infinity-Posibility.py
File metadata and controls
166 lines (150 loc) · 4.41 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import time
from typing import Optional, Callable
try:
from asyncio.windows_events import NULL
except:
pass
from turtle import *
import random
def wait(timer=1, repeats=1):
for i in range(repeats):
time.sleep(timer)
def end_script():
print('_______________________')
print('Made with "Infinity-Posbility" module.')
exit()
def draw_squares(Pattern=False,times=10, size=30):
for i in range(times):
for i in range(4):
forward(30)
right(90)
if Pattern:
forward(32)
right(45)
forward(18)
else:
forward(random.randint(20, 45))
right(random.randint(2, 182))
forward(random.randint(4, 25))
list1 = []
def get_random_number(min=0, max=10):
return random.randint(min,max)
def log(log: str="Hello world!", print: bool = False, list: bool = False, returner: bool = False):
if print:
print(log)
elif list:
global list1
list2 = []
list1.append(log)
list1.purpose = "logged-list"
list2.append(log)
list2.purpose = "logged-list"
return list2
else:
return log
# Default code if ran as a program:
if __name__ == '__main__':
print("Reminder: The code is supposed to be used as a module!")
draw_squares(True,15)
class Maped:
def __init__(self, value):
self.value = value
self.splitt = None
def split(self, char=';', get=True):
char = str(char)
to_return = []
join = ''
value = self.value
for c in value:
if c != char:
join += c
else:
to_return.append(join)
join = ''
to_return.append(join)
self.splitt = to_return
if get:
return to_return
def unsplit(self, char=';', split=None):
if split is None:
split = self.splitt
value = char.join(split)
self.value = value
return value
def __str__(self):
return f"<{self.__class__.__name__} Class: {self.__class__}, data: <value: <{self.value}>, split: <{self.splitt}>>>"
def __repr__(self):
return f"{self.__class__.__name__} Class: {self.__class__}, data: <value: <{self.value}>, split: <{self.splitt}>>"
def get_logs_list():
global list1
return list1
def clear_logs_list():
global list1
list1 = []
# Code Class
class Code:
def __init__(self, code_func: callable, handle_errors: bool = False):
self.code_func: callable = code_func
self.handle_errors: bool = handle_errors
def __repr__(self):
return f"Code Object: {self.code_func}|{self.handle_errors}"
def check(self) -> bool:
if self.code_func is not None:
try:
if isinstance(self.code_func, callable):
return True
else:
return False
except Exception:
return False
return False
def __eq__(self, other):
if isinstance(other, Code):
try:
return self.code_func == other.code_func and self.check() == other.check()
except Exception as e:
return False
return False
def run(self):
if self.handle_errors:
try:
self.code_func()
except Exception as e:
raise SystemError("Error at running code inside a Code class. Disable handle_errors to get the normal message") from e
else:
self.code_func()
def delete(self) -> bool:
try:
self.code_func: callable | None = None
return True
except Exception as e:
return False
def realistic_round(num):
rounding_factor: int = 1
rounded_num = decimal.Decimal(num / rounding_factor).quantize(decimal.Decimal('1'), rounding=decimal.ROUND_HALF_UP)
return float(rounded_num * rounding_factor)
def log_to_file(file: str, mode: str, *messages) -> None:
"""
Logs a message.
Parameters:
file: str --- File name;
mode: str --- Write Mode;
*messages --- Messages to write;
Output -> None;
"""
message = ' '.join(messages)
with open(file, mode) as f:
f.write(message)
def delete_logs(file: str) -> None:
"""
Deletes a log file.
Parameters:
file: str --- File name;
Output -> None;
Requirements:
file: str must end in '.txt', '.out', '.log' or '.logs';
"""
if file.endswith(".txt") or file.endswith(".out") or file.endswith(".log") or file.endswith(".logs"):
remove(file)
else:
raise Exception(f"Error at deleting file '{file}'. Reason: file may not be a logs file. Use os.remove() to remove the file instead.")