-
Notifications
You must be signed in to change notification settings - Fork 1
/
auto_params.py
53 lines (47 loc) · 1.4 KB
/
auto_params.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
from typing import Any
class AutoParams:
def __init__(self, seqs: dict[str, Any]):
self.params = seqs
def next(self, key):
"""从集合中取对象的下一个迭代值
int : += 1
list: pop()
"""
value = self.params[key]
if isinstance(value, int):
self.params[key] = value + 1
return value
elif isinstance(value, list):
return value.pop()
else:
raise TypeError()
def get(self, key):
"""从集合中取对象的值"""
value = self.params[key]
return value
# if isinstance(value, int):
# return value
# elif isinstance(value, str):
# return value
# elif isinstance(value, list):
# return value[-1]
# else:
# raise TypeError()
def pick(self, params_key, key, key2=None):
"""从集合中取出对象
dict: pop()
"""
if key2:
value = self.params[params_key][key]
if isinstance(value, dict):
return value.pop(key2)
else:
raise TypeError()
else:
value = self.params[params_key]
if isinstance(value, dict):
return value.pop(key)
else:
raise TypeError()
def reset(self, str, value):
self.params[str] = value