-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautils.py
More file actions
105 lines (78 loc) · 2.42 KB
/
autils.py
File metadata and controls
105 lines (78 loc) · 2.42 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
# -*- coding: utf-8 -*-
from typing import overload
from typing import Iterable, Any, Hashable, SupportsInt
from cmd import Cmd
from itertools import product
from string import printable, ascii_uppercase
from os import system
def cls() -> None:
system('cls')
@overload
def strl(arg: Iterable, sep = '') -> str: ...
@overload
def strl(*arg: Any, sep = '') -> str: ...
def strl(*arg, sep = '') -> str:
if (len(arg) == 1):
return ''.join(arg[0])
return ''.join(arg)
@overload
def uniquel(arg: Iterable) -> bool: ...
@overload
def uniquel(*arg: Hashable) -> bool: ...
def uniquel(*arg) -> bool:
if (len(arg) == 1):
return len(arg[0]) == len(set(arg[0]))
return len(arg) == len(set(arg))
def uniques(s: str) -> bool:
return uniquel(list(s))
def products(s: str) -> product:
return product(s, repeat = len(s))
def convert(intr: int, base: int) -> str:
res = []
run = 0
while (intr != 0):
run = intr % base
res.append(run)
intr = intr // base
return strl([dict(enumerate([char for char in printable if char not in ascii_uppercase]))[i] for i in res[::-1]])
def lto(targetType, seq: Iterable) -> Iterable:
try:
return type(seq)(targetType(i) for i in seq)
except TypeError:
return list(targetType(i) for i in seq)
@overload
def printl(arg: Iterable): ...
@overload
def printl(*arg: Any): ...
def printl(*arg):
cmd = Cmd()
if (len(arg) == 1):
cmd.columnize([str(item) for item in arg[0]])
return
cmd.columnize([str(item) for item in arg])
@overload
def pdt(arg: Iterable): ...
@overload
def pdt(*arg: Any): ...
def pdt(arg: Iterable) -> SupportsInt:
if (len(arg) == 1):
p = 1
for item in arg[0]:
p *= item
return p
p = 1
for item in arg:
p *= item
return p
def fread(name: str, encoding: str = 'utf-8', **kwargs) -> str | bytes | Any:
'''
Чтение данных из файла с заданным именем и параметрами открытия.
'''
with open(name, encoding = encoding, **kwargs) as f:
return f.read()
def fwrite(name: str, data, encoding: str = 'utf-8', mode = 'w', **kwargs) -> None:
'''
Запись данных в файл с заданным именем и параметрами открытия.
'''
with open(name, mode, encoding = encoding, **kwargs) as f:
f.write(data)