-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pointers.py
125 lines (89 loc) · 3.89 KB
/
Pointers.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
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
class TransDict:
def __init__(self,items):
self.items:dict = items
for i in self.items:
self.globals = globals()[i]= items[i]
def _(self,_globals):
return(_globals.update(globals()))
def getdictval_value(self,string:str):
return [t for x, t in enumerate(self.items) if t==string][0]
def getdictval_index(self,index:int):
return [t for x, t in enumerate(self.items) if x==int(index)][0]
def add_prefix_all(self,prefix_a):
for p in self.items:
pref = f'{prefix_a}{p}'
self.globals = globals()[pref]= self.items[p]
def add_suffix_all(self,suffix_a):
for s in self.items:
suff = f'{s}{suffix_a}'
self.varname = suff
self.globals = globals()[suff]= self.items[s]
def add_prefix(self,prefix=None,index:int=None,value:str=None):
"""
Add a prefix to the current variable that has been created
"""
if value is None:
self.globals = globals()[f'{prefix}{self.getdictval_index(index)}']= self.items[self.getdictval_index(index)]
if index is None:
self.globals = globals()[f'{prefix}{self.getdictval_value(value)}']= self.items[self.getdictval_value(value)]
def add_suffix(self,suffix=None,index:int=None,value:str=None):
"""
Add a suffix to the current variable that has been created using either the index or the value to identify which a prefix should be added to.`
add_suffix(
suffix='_1'
index='0'
)
"""
if value is None:
self.globals = globals()[f'{self.getdictval_index(index)}{suffix}']= self.items[self.getdictval_index(index)]
if index is None:
self.globals = globals()[f'{self.getdictval_value(value)}{suffix}']= self.items[self.getdictval_value(value)]
class TransIndv:
def __init__(self,item,value):
""" app"""
self.item = item
self.globals = globals()[item]= value
def _(self,_globals):
return(_globals.update(globals()))
def getdictval_value(self,string:str):
return [t for x, t in enumerate(self.items) if t==string][0]
def getdictval_index(self,index:int):
return [t for x, t in enumerate(self.items) if x==int(index)][0]
def add_prefix(self,prefix_a):
pref = f'{self.item}{prefix_a}'
self.globals = globals()[pref]= self.item
def add_suffix(self,suffix_a):
suff = f'{suffix_a}{self.item}'
self.varname = suff
self.globals = globals()[suff]= self.items
class TransFile:
def __init__(self,filename):
try:
file = open(filename,'r')
except FileNotFoundError:
print("{} is not in directory".format(filename))
else:
files = file.readlines()
box = {}
for i in files:
i = i.strip('\n')
nam = i.split('=')
for i in range(50):
space = ' '*i
nam[0]=nam[0].replace(space,'')
nam[1]=nam[1].replace(space,'')
box[nam[0]] =nam[1]
self.box = box
def _(self,_globals):
return(_globals.update(globals()))
def init(self):
self.newd = TransDict(self.box)
def init_prefix(self,prefix):
self.newd.add_prefix_all(prefix)
def init_suffix(self,suffix):
self.newd.add_suffix_all(suffix)
def print_var(self):
print(f' {len(self.box)} Variables Created: ')
for num,los in enumerate(self.box):
statement = '[{}] {}={}'.format(num,los,self.box[los])
print(statement)