byzh-core 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. byzh_core-0.0.1/LICENSE +21 -0
  2. byzh_core-0.0.1/PKG-INFO +18 -0
  3. byzh_core-0.0.1/README.md +8 -0
  4. byzh_core-0.0.1/byzh_core/Barchive/__init__.py +3 -0
  5. byzh_core-0.0.1/byzh_core/Barchive/archive.py +67 -0
  6. byzh_core-0.0.1/byzh_core/Bbasic/__init__.py +3 -0
  7. byzh_core-0.0.1/byzh_core/Bbasic/text_style.py +76 -0
  8. byzh_core-0.0.1/byzh_core/Bconfig/__init__.py +3 -0
  9. byzh_core-0.0.1/byzh_core/Bconfig/config.py +328 -0
  10. byzh_core-0.0.1/byzh_core/Bmath/__init__.py +4 -0
  11. byzh_core-0.0.1/byzh_core/Bmath/divides.py +41 -0
  12. byzh_core-0.0.1/byzh_core/Bmath/get_norm.py +21 -0
  13. byzh_core-0.0.1/byzh_core/Btable/__init__.py +6 -0
  14. byzh_core-0.0.1/byzh_core/Btable/auto_table.py +427 -0
  15. byzh_core-0.0.1/byzh_core/Btable/obsolete/__init__.py +0 -0
  16. byzh_core-0.0.1/byzh_core/Btable/obsolete/b_auto_table.py +321 -0
  17. byzh_core-0.0.1/byzh_core/Btable/row_table.py +175 -0
  18. byzh_core-0.0.1/byzh_core/Btable/xy_table.py +211 -0
  19. byzh_core-0.0.1/byzh_core/Bterminal/__init__.py +3 -0
  20. byzh_core-0.0.1/byzh_core/Bterminal/cmd.py +116 -0
  21. byzh_core-0.0.1/byzh_core/Btqdm/__init__.py +4 -0
  22. byzh_core-0.0.1/byzh_core/Btqdm/b_tqdm.py +76 -0
  23. byzh_core-0.0.1/byzh_core/Bwriter/__init__.py +5 -0
  24. byzh_core-0.0.1/byzh_core/Bwriter/globalwriter.py +62 -0
  25. byzh_core-0.0.1/byzh_core/Bwriter/writer.py +138 -0
  26. byzh_core-0.0.1/byzh_core/__init__.py +5 -0
  27. byzh_core-0.0.1/byzh_core.egg-info/PKG-INFO +18 -0
  28. byzh_core-0.0.1/byzh_core.egg-info/SOURCES.txt +31 -0
  29. byzh_core-0.0.1/byzh_core.egg-info/dependency_links.txt +1 -0
  30. byzh_core-0.0.1/byzh_core.egg-info/requires.txt +1 -0
  31. byzh_core-0.0.1/byzh_core.egg-info/top_level.txt +1 -0
  32. byzh_core-0.0.1/setup.cfg +4 -0
  33. byzh_core-0.0.1/setup.py +18 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [2024] [zhengyu]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 2.1
2
+ Name: byzh_core
3
+ Version: 0.0.1
4
+ Summary: byzh_core是byzh系列的核心库,包含了一些常用的工具函数和类。
5
+ Author: byzh_rc
6
+ License: MIT
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Requires-Dist: wcwidth
10
+
11
+ # progressBar.py
12
+ just like tqdm
13
+
14
+ # log.py
15
+ jsut like loguru
16
+
17
+ # train.py
18
+ provide Trainer
@@ -0,0 +1,8 @@
1
+ # progressBar.py
2
+ just like tqdm
3
+
4
+ # log.py
5
+ jsut like loguru
6
+
7
+ # train.py
8
+ provide Trainer
@@ -0,0 +1,3 @@
1
+ from .archive import b_archive_zip
2
+
3
+ __all__ = ['b_archive_zip']
@@ -0,0 +1,67 @@
1
+ import os
2
+ import zipfile
3
+
4
+ def b_archive_zip(
5
+ source_path,
6
+ output_path,
7
+ exclude_dirs:list[str]=None,
8
+ exclude_files:list[str]=None,
9
+ exclude_exts:list[str]=None,
10
+ while_list:list[str]=None,
11
+ contain_empty_folder:bool=True,
12
+ ):
13
+ '''
14
+ 压缩文件夹,排除 指定文件夹and指定后缀文件
15
+ :param source_path:
16
+ :param output_path:
17
+ :param exclude_dirs: ['__pycache__', '.git', '.idea']
18
+ :param exclude_files: ['.gitignore', 'README.md']
19
+ :param exclude_exts: ['.csv', '.npy', '.pt', '.pth']
20
+ :return:
21
+ '''
22
+ if exclude_dirs is None:
23
+ exclude_dirs = []
24
+ if exclude_files is None:
25
+ exclude_files = []
26
+ if exclude_exts is None:
27
+ exclude_exts = []
28
+ if while_list is None:
29
+ while_list = []
30
+
31
+ with zipfile.ZipFile(output_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
32
+ # 压缩文件:
33
+ if os.path.isfile(source_path):
34
+ arcname = os.path.basename(source_path)
35
+ zipf.write(source_path, arcname)
36
+ return
37
+
38
+ # 压缩文件夹:
39
+ if os.path.isdir(source_path):
40
+ for root, dirs, files in os.walk(source_path):
41
+ # 排除指定文件夹dirs
42
+ dirs[:] = [d for d in dirs if d in while_list or d not in exclude_dirs]
43
+ # 排除指定文件files
44
+ files = [f for f in files if f in while_list or f not in exclude_files]
45
+ # 排除指定后缀文件files
46
+ files = [f for f in files if f in while_list or not any(f.endswith(ext) for ext in exclude_exts)]
47
+
48
+
49
+ # 压缩文件:
50
+ for file in files:
51
+ file_path = os.path.join(root, file)
52
+ arcname = os.path.relpath(file_path, source_path) # 相对于source_path的相对路径
53
+ zipf.write(file_path, arcname)
54
+
55
+ # 若是空文件夹,则压缩文件夹:
56
+ if contain_empty_folder and (len(dirs) == 0 and len(files) == 0):
57
+ arcname = os.path.relpath(root, source_path)
58
+ folder_path = root
59
+ zipf.write(folder_path, arcname)
60
+
61
+ if __name__ == '__main__':
62
+ b_archive_zip(
63
+ source_path=r'E:\byzh_workingplace\byzh-rc-to-pypi\awa',
64
+ output_path=r'E:\byzh_workingplace\byzh-rc-to-pypi\awaqwq.zip',
65
+ exclude_dirs=['__pycache__', 'com'],
66
+ exclude_exts=['.ppt']
67
+ )
@@ -0,0 +1,3 @@
1
+ from .text_style import B_Color, B_Appearance, B_Background
2
+
3
+ __all__ = ['B_Color', 'B_Appearance', 'B_Background']
@@ -0,0 +1,76 @@
1
+ # 字体颜色
2
+ class B_Color:
3
+ RESET = "\033[0m"
4
+
5
+ BLACK = "\033[30m" # 黑
6
+ RED = "\033[31m" # 红
7
+ GREEN = "\033[32m" # 绿
8
+ YELLOW = "\033[33m" # 黄
9
+ BLUE = "\033[34m" # 蓝
10
+ PURPLE = "\033[35m" # 紫/粉
11
+ CYAN = "\033[36m" # 青/蓝绿
12
+ SILVER = "\033[37m" # 灰/银
13
+
14
+ # 背景颜色
15
+ class B_Background:
16
+ RESET = "\033[0m"
17
+
18
+ BLACK = "\033[40m" # 黑
19
+ RED = "\033[41m" # 红
20
+ GREEN = "\033[42m" # 绿
21
+ YELLOW = "\033[43m" # 黄
22
+ BLUE = "\033[44m" # 蓝
23
+ PURPLE = "\033[45m" # 紫/粉
24
+ CYAN = "\033[46m" # 青/蓝绿
25
+ SILVER = "\033[47m" # 灰/银
26
+
27
+ # 效果
28
+ class B_Appearance:
29
+ RESET = "\033[0m"
30
+
31
+ HIGHLIGHT = "\033[1m" # 高亮
32
+ LOWLIGHT = "\033[2m" # 低亮
33
+ UNDERLINE = "\033[4m" # 下划线
34
+ REVERSE = "\033[7m" # 反显(白底黑字)
35
+
36
+
37
+ if __name__ == '__main__':
38
+ print("以下是测试文字:")
39
+
40
+ print("\033[0m默认文字\033[0m")
41
+ print("\033[1m高亮文字\033[0m")
42
+ print("\033[2m低亮文字\033[0m")
43
+ # print("\033[3m无效文字\033[0m")
44
+ print("\033[4m下划线文字\033[0m")
45
+ print("\033[5m闪烁文字(无效)\033[0m")
46
+ # print("\033[6m无效文字\033[0m")
47
+ print("\033[7m反显文字\033[0m")
48
+ print("\033[8m消隐文字(无效)\033[0m")
49
+
50
+ print("\n\033[31;1m字体颜色\033[0m测试文字")
51
+ print("\033[30m低亮黑色文字\033[0m\t\033[30;1m高亮黑色文字\033[0m")
52
+ print("\033[31m低亮红色文字\033[0m\t\033[31;1m高亮红色文字\033[0m")
53
+ print("\033[32m低亮绿色文字\033[0m\t\033[32;1m高亮绿色文字\033[0m")
54
+ print("\033[33m低亮黄色文字\033[0m\t\033[33;1m高亮黄色文字\033[0m")
55
+ print("\033[34m低亮蓝色文字\033[0m\t\033[34;1m高亮蓝色文字\033[0m")
56
+ print("\033[35m低亮紫色文字\033[0m\t\033[35;1m高亮紫色文字\033[0m")
57
+ print("\033[36m低亮青色文字\033[0m\t\033[36;1m高亮青色文字\033[0m")
58
+ print("\033[37m低亮灰色文字\033[0m\t\033[37;1m高亮灰色文字\033[0m")
59
+ # print("\033[38m测试文字\033[0m")
60
+ # print("\033[39m测试文字\033[0m")
61
+
62
+ print("\n\033[31;1m背景颜色\033[0m测试文字")
63
+ print("\033[40m低亮文字黑色背景\033[0m\t\033[40;1m高亮文字黑色背景\033[0m")
64
+ print("\033[41m低亮文字红色背景\033[0m\t\033[41;1m高亮文字红色背景\033[0m")
65
+ print("\033[42m低亮文字绿色背景\033[0m\t\033[42;1m高亮文字绿色背景\033[0m")
66
+ print("\033[43m低亮文字黄色背景\033[0m\t\033[43;1m高亮文字黄色背景\033[0m")
67
+ print("\033[44m低亮文字蓝色背景\033[0m\t\033[44;1m高亮文字蓝色背景\033[0m")
68
+ print("\033[45m低亮文字紫色背景\033[0m\t\033[45;1m高亮文字紫色背景\033[0m")
69
+ print("\033[46m低亮文字青色背景\033[0m\t\033[46;1m高亮文字青色背景\033[0m")
70
+ print("\033[47m低亮文字灰色背景\033[0m\t\033[47;1m高亮文字灰色背景\033[0m")
71
+ # print("\033[48m测试文字\033[0m")
72
+ # print("\033[49m测试文字\033[0m")
73
+
74
+
75
+
76
+
@@ -0,0 +1,3 @@
1
+ from .config import B_Config
2
+
3
+ __all__ = ['B_Config']
@@ -0,0 +1,328 @@
1
+ from ..Bbasic import B_Color
2
+
3
+
4
+ class B_Config:
5
+ def __init__(self):
6
+ super().__init__()
7
+ self.group_lst = []
8
+ self.dict_lst = []
9
+
10
+ # set-方法
11
+ def set(self, group, key, value):
12
+ '''
13
+ 添加元素
14
+ '''
15
+ if not isinstance(group, str):
16
+ raise Exception(f"{B_Color.YELLOW}group({str(group)}) must be str{B_Color.RESET}")
17
+ if not isinstance(key, str):
18
+ raise Exception(f"{B_Color.YELLOW}key({str(key)}) must be str{B_Color.RESET}")
19
+
20
+ if group not in self.group_lst:
21
+ self.group_lst.append(group)
22
+ self.dict_lst.append(dict())
23
+
24
+ index = self._get_index(group)
25
+ self.dict_lst[index][key] = value
26
+
27
+ def set_copygroup(self, dst_group, src_group):
28
+ '''
29
+ 通过复制group来快速添加组
30
+ '''
31
+ if not isinstance(dst_group, str):
32
+ raise Exception(f"{B_Color.YELLOW}group({str(dst_group)}) must be str{B_Color.RESET}")
33
+ if not isinstance(src_group, str):
34
+ raise Exception(f"{B_Color.YELLOW}group({str(src_group)}) must be str{B_Color.RESET}")
35
+ if dst_group in self.group_lst:
36
+ raise Exception(f"{B_Color.YELLOW}group({str(dst_group)}) already exist{B_Color.RESET}")
37
+
38
+ import copy
39
+ self.group_lst.append(dst_group)
40
+ self.dict_lst.append(copy.deepcopy(self.dict_lst[self._get_index(src_group)]))
41
+
42
+ def set_dictgroup(self, group, dict):
43
+ '''
44
+ 通过dict来快速添加组
45
+ '''
46
+ if group in self.group_lst:
47
+ raise Exception(f"{B_Color.YELLOW}group({str(group)}) already exist{B_Color.RESET}")
48
+ self.group_lst.append(group)
49
+ # 把dict的键值对都化为字符串
50
+ self.dict_lst.append({str(key): str(value) for key, value in dict.items()})
51
+
52
+ # show-方法
53
+ def show_all(self):
54
+ '''
55
+ 打印config
56
+ '''
57
+ print(f"group_cnt({len(self.group_lst)}) | {self.group_lst} \ndict_cnt:{len(self.dict_lst)}")
58
+ print()
59
+ for group, dict in zip(self.group_lst, self.dict_lst):
60
+ print(f"{group}:\n\t{dict}")
61
+
62
+ def show_group(self, group):
63
+ '''
64
+ 打印某个group
65
+ '''
66
+ result = self._get_group_str(group)
67
+ print(group + ":\n" + result)
68
+
69
+ # get-方法
70
+ def get_str(self, group, key):
71
+ '''
72
+ 获取某个group的某个key的值
73
+ '''
74
+ self._check(group, key)
75
+ index = self._get_index(group)
76
+ return str(self.dict_lst[index][key])
77
+
78
+ def get_int(self, group, key):
79
+ '''
80
+ 获取某个group的某个key的值
81
+ '''
82
+ self._check(group, key)
83
+ index = self._get_index(group)
84
+ return int(self.dict_lst[index][key])
85
+
86
+ def get_float(self, group, key):
87
+ '''
88
+ 获取某个group的某个key的值
89
+ '''
90
+ self._check(group, key)
91
+ index = self._get_index(group)
92
+ return float(self.dict_lst[index][key])
93
+
94
+ def get_bool(self, group, key):
95
+ '''
96
+ 获取某个group的某个key的值\n
97
+ 只有value为["False", "0", "None"]时,返回False
98
+ '''
99
+ self._check(group, key)
100
+
101
+ if self.get_str(group, key) in ["False", "0", "None"]:
102
+ return False
103
+ elif self.get_str(group, key) in ["True", "1"]:
104
+ return True
105
+ else:
106
+ raise Exception(f"{B_Color.YELLOW}value({str(key)}) cannot change to bool{B_Color.RESET}")
107
+
108
+ # save-方法
109
+ def to_pickle(self, path):
110
+ '''
111
+ 保存为pickle文件(最稳定的方式)
112
+ '''
113
+ import pickle
114
+ with open(path, 'wb') as f:
115
+ pickle.dump([self.group_lst, self.dict_lst], f)
116
+
117
+ def from_pickle(self, path):
118
+ '''
119
+ 从pickle文件中读取
120
+ '''
121
+ import pickle
122
+ with open(path, 'rb') as f:
123
+ [self.group_lst, self.dict_lst] = pickle.load(f)
124
+
125
+ def to_json(self, path):
126
+ '''
127
+ 保存为json文件
128
+ '''
129
+ import json
130
+ with open(path, 'w') as f:
131
+ for group, group_dict in zip(self.group_lst, self.dict_lst):
132
+ entry = {"group": group, "dict": group_dict}
133
+ json.dump(entry, f)
134
+ f.write("\n")
135
+
136
+ def from_json(self, path):
137
+ '''
138
+ 从json文件中读取
139
+ '''
140
+ import json
141
+ with open(path, 'r') as f:
142
+ self.group_lst = []
143
+ self.dict_lst = []
144
+ for line in f:
145
+ entry = json.loads(line.strip())
146
+ self.group_lst.append(entry["group"])
147
+ self.dict_lst.append(entry["dict"])
148
+
149
+ def to_yaml(self, path):
150
+ '''
151
+ 保存为yaml文件
152
+ '''
153
+ import yaml
154
+ with open(path, 'w') as f:
155
+ yaml.dump([self.group_lst, self.dict_lst], f)
156
+
157
+ def from_yaml(self, path):
158
+ '''
159
+ 从yaml文件中读取
160
+ '''
161
+ import yaml
162
+ with open(path, 'r') as f:
163
+ [self.group_lst, self.dict_lst] = yaml.load(f, Loader=yaml.FullLoader)
164
+
165
+ def to_ini(self, path):
166
+ '''
167
+ 保存为ini文件
168
+ '''
169
+ with open(path, 'w') as f:
170
+ for group, dict in zip(self.group_lst, self.dict_lst):
171
+ f.write(f"[{group}]\n")
172
+ for key, value in dict.items():
173
+ f.write(f"{key} = {value}\n")
174
+ f.write("\n")
175
+
176
+ def from_ini(self, path):
177
+ '''
178
+ 从ini文件中读取
179
+ '''
180
+ self.group_lst = []
181
+ self.dict_lst = []
182
+ with open(path, 'r') as f:
183
+ lines = f.readlines()
184
+ dictionary = dict()
185
+ for line in lines:
186
+ line = line.strip()
187
+ if line.startswith('[') and line.endswith(']'):
188
+ # 如果字典非空不是dict()
189
+ if dictionary != dict():
190
+ self.dict_lst.append(dictionary.copy())
191
+ dictionary.clear()
192
+ group = line[1:-1]
193
+ self.group_lst.append(group)
194
+ elif line == '':
195
+ continue
196
+ else:
197
+ if '=' in line:
198
+ key, value = line.split('=', 1)
199
+ # key和value去除前后空格
200
+ key = key.strip()
201
+ value = value.strip()
202
+ dictionary[key] = value
203
+ else:
204
+ dictionary[line] = ''
205
+ if dictionary != dict():
206
+ self.dict_lst.append(dictionary.copy())
207
+
208
+ def to_csv(self, path):
209
+ '''
210
+ 保存为csv文件
211
+ '''
212
+ import csv
213
+ with open(path, 'w', newline='') as f:
214
+ writer = csv.writer(f)
215
+
216
+ # Write header: the first row is group names
217
+ header = ['key'] + self.group_lst
218
+ writer.writerow(header)
219
+
220
+ # Find all unique keys across all groups
221
+ all_keys = set()
222
+ for group_dict in self.dict_lst:
223
+ all_keys.update(group_dict.keys())
224
+
225
+ # Write rows for each key
226
+ for key in all_keys:
227
+ row = [key]
228
+ for group_dict in self.dict_lst:
229
+ row.append(group_dict.get(key, '')) # Add value or empty if key is not present
230
+ writer.writerow(row)
231
+
232
+ def from_csv(self, path):
233
+ '''
234
+ 从csv文件中读取
235
+ '''
236
+ import csv
237
+ with open(path, 'r') as f:
238
+ reader = csv.reader(f)
239
+
240
+ # Read header: the first row is group names
241
+ header = next(reader)
242
+ group_lst = header[1:] # The first column is 'key', rest are groups
243
+ self.group_lst = group_lst
244
+ self.dict_lst = [{} for _ in range(len(group_lst))] # Initialize dicts for each group
245
+
246
+ # Read the key-value pairs
247
+ for row in reader:
248
+ key = row[0]
249
+ for i, value in enumerate(row[1:], start=0):
250
+ if value: # Only add value if it's not empty
251
+ self.dict_lst[i][key] = value
252
+
253
+ def to_table(self, path):
254
+ from ..Btable import B_AutoTable
255
+ my_table = B_AutoTable()
256
+ for index, group in enumerate(self.group_lst):
257
+ for key, value in self.dict_lst[index].items():
258
+ my_table[group][key] = value
259
+
260
+ my_table.to_txt(path)
261
+
262
+ # 工具-方法
263
+ def __str__(self):
264
+ result = ""
265
+ for group in self.group_lst:
266
+ result += group + ":\n"
267
+ result += self._get_group_str(group) + "\n"
268
+ # 去掉最后一个\n
269
+ result = result[:-1]
270
+ return result
271
+ def __getitem__(self, item):
272
+ return self.dict_lst[item]
273
+
274
+ def __setitem__(self, key, value):
275
+ self.set_dictgroup(key, value)
276
+
277
+ def _get_index(self, group):
278
+ return self.group_lst.index(group)
279
+
280
+ def _get_group_str(self, group):
281
+ self._check(group)
282
+ index = self._get_index(group)
283
+ result = "\n".join([f"\t({key} -> {value})" for key, value in self.dict_lst[index].items()])
284
+ return result
285
+
286
+ def _check(self, group, key=None):
287
+ # 检查group是否是字符串
288
+ if not isinstance(group, str):
289
+ raise Exception(f"{B_Color.YELLOW}group({str(group)}) must be str{B_Color.RESET}")
290
+ # 检查group是否在group_list中
291
+ if group not in self.group_lst:
292
+ raise Exception(f"{B_Color.YELLOW}group({str(group)}) not found{B_Color.RESET}")
293
+
294
+ if key is not None:
295
+ # 检查key是否是字符串
296
+ if not isinstance(key, str):
297
+ raise Exception(f"{B_Color.YELLOW}key({str(key)}) must be str{B_Color.RESET}")
298
+ # 检查key是否在dict中
299
+ index = self._get_index(group)
300
+ if key not in self.dict_lst[index]:
301
+ raise Exception(f"{B_Color.YELLOW}key({str(key)}) not found{B_Color.RESET}")
302
+
303
+
304
+ if __name__ == '__main__':
305
+ a = B_Config()
306
+
307
+ a.set('awa', 'a', 'None')
308
+ a.set('awa', 'b', '123')
309
+ a.set('awa', '345', '33333')
310
+
311
+ a.set('awa', 'a532', 'No32ne')
312
+ a.set('awa', 'b13', '123412')
313
+ a.set('awa', '321345', '33342333')
314
+
315
+ a.set_copygroup('default', 'qwq')
316
+ a.set('qwq', '345', 'aaaaaa')
317
+
318
+ a.to_csv('config.csv')
319
+ a.from_csv('config.csv')
320
+ # a.to_yaml('config.yaml')
321
+ # a.from_yaml('config.yaml')
322
+ # a.to_pickle('config.pkl')
323
+ # a.from_pickle('config.pkl')
324
+ # a.to_json('config.json')
325
+ # a.from_json('config.json')
326
+
327
+ print(a.get_str('awa', 'b13'))
328
+ print(a)
@@ -0,0 +1,4 @@
1
+ from .divides import b_divides
2
+ from .get_norm import b_get_norm
3
+
4
+ __all__ = ['b_divides', 'b_get_norm']
@@ -0,0 +1,41 @@
1
+ from typing import Union, List, Set, Tuple
2
+
3
+ my_type1 = Union[int, float, str]
4
+ def get_num(num: my_type1):
5
+ if isinstance(num, str):
6
+ return float(num)
7
+ return num
8
+
9
+ my_type2 = Union[my_type1, List[my_type1], Set[my_type1], Tuple[my_type1]]
10
+ def b_divides(iterUp: my_type2, iterDown: my_type2):
11
+ """
12
+ 支持list, tuple, set, 单个数\n
13
+ iterUp as 分子\n
14
+ iterDown as 分母
15
+ """
16
+ up = 1
17
+ down = 1
18
+
19
+ if not isinstance(iterUp, list) and not isinstance(iterUp, tuple) and not isinstance(iterUp, set):
20
+ up *= get_num(iterUp)
21
+ else:
22
+ for x in iterUp:
23
+ up *= get_num(x)
24
+
25
+ if not isinstance(iterDown, list) and not isinstance(iterDown, tuple) and not isinstance(iterDown, set):
26
+ down *= get_num(iterDown)
27
+ else:
28
+ for x in iterDown:
29
+ down *= get_num(x)
30
+
31
+ return up / down
32
+
33
+ if __name__ == '__main__':
34
+ result = b_divides([1, 2, 3], [4, 5])
35
+ print(result)
36
+
37
+ result = b_divides(6.63e-34, (9.11e-31, 3e8))
38
+ print(result)
39
+
40
+ result = b_divides('6.63e-34', ['9.11e-31', 3e8])
41
+ print(result)
@@ -0,0 +1,21 @@
1
+ from typing import Literal
2
+ def b_get_norm(
3
+ lst: list,
4
+ mode: Literal['min-max'] = 'min-max',
5
+ ndigits: int | None = None
6
+ ) -> tuple[list, float, float]:
7
+
8
+ if mode =='min-max':
9
+ minimum = min(lst)
10
+ maximum = max(lst)
11
+ if ndigits is None:
12
+ result = [(x-minimum)/(maximum-minimum) for x in lst]
13
+ else:
14
+ result = [round((x-minimum)/(maximum-minimum), ndigits) for x in lst]
15
+ return (result, minimum, maximum)
16
+
17
+
18
+ if __name__ == '__main__':
19
+ lst = [1, 2, 3, 4, 5]
20
+ result = b_get_norm(lst)
21
+ print(result)
@@ -0,0 +1,6 @@
1
+ from .row_table import B_RowTable
2
+ from .xy_table import B_XYTable
3
+ from .auto_table import B_AutoTable
4
+
5
+
6
+ __all__ = ['B_RowTable', 'B_XYTable', 'B_AutoTable']