byzh-core 0.0.2.5__py3-none-any.whl → 0.0.2.6__py3-none-any.whl

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.
@@ -251,8 +251,8 @@ class B_Config:
251
251
  self.dict_lst[i][key] = value
252
252
 
253
253
  def to_table(self, path):
254
- from ..Btable import B_AutoTable
255
- my_table = B_AutoTable()
254
+ from ..Btable import B_Table2d
255
+ my_table = B_Table2d()
256
256
  for index, group in enumerate(self.group_lst):
257
257
  for key, value in self.dict_lst[index].items():
258
258
  my_table[group][key] = value
@@ -60,7 +60,7 @@ class Matrix2d:
60
60
  def __init__(self, row_name='x', col_name='y'):
61
61
  self.row_name = row_name
62
62
  self.col_name = col_name
63
- self.matrix = [[row_name + ' | ' + col_name]]
63
+ self.matrix = [[row_name + ' \\ ' + col_name]]
64
64
 
65
65
  def get_rows(self): # 包含left_upper
66
66
  if self.matrix == [[]]:
@@ -151,9 +151,14 @@ class Dict1d:
151
151
 
152
152
  def __getitem__(self, key):
153
153
  key = str(key)
154
- return self.dict[key]
154
+ try:
155
+ return self.dict[key]
156
+ except KeyError:
157
+ return None
155
158
  def __setitem__(self, key, value): # 用于最底层赋值
156
159
  key, value = str(key), str(value)
160
+ if value == 'None':
161
+ value = ' '
157
162
  self.dict[key] = value
158
163
  def set(self, key, value): # 用于非底层赋值(防止把子dict变为str)
159
164
  key = str(key)
@@ -214,6 +219,26 @@ class B_Table2d:
214
219
  # 判断是否改变
215
220
  self.is_changed = False
216
221
 
222
+ def set(self, row, col, content):
223
+ row, col, content = str(row), str(col), str(content)
224
+ self[row][col] = content
225
+
226
+ def get_str(self, row, col):
227
+ return self[row][col]
228
+ def get_int(self, row, col):
229
+ return int(self[row][col])
230
+ def get_float(self, row, col):
231
+ return float(self[row][col])
232
+ def get_bool(self, row, col):
233
+ '''
234
+ 如果是字符串"True"或"1",返回True,否则返回False
235
+ '''
236
+ temp = self[row][col]
237
+ if temp == "True" or temp == "1":
238
+ return True
239
+ else:
240
+ return False
241
+
217
242
  def __getitem__(self, row):
218
243
  self.is_changed = True
219
244
 
@@ -226,13 +251,19 @@ class B_Table2d:
226
251
  row = str(row)
227
252
  self.dict2d[row] = new_dict
228
253
 
229
- def from_txt(self, txt_path, use_txt_name:bool=False):
254
+ def from_txt(self, txt_path, create:bool=False, use_txt_name:bool=False):
230
255
  '''
231
-
232
256
  :param txt_path:
257
+ :param create: 如果文件不存在,则创建
233
258
  :param use_txt_name: 默认使用init时的row_name和col_name
234
259
  :return:
235
260
  '''
261
+ if not os.path.exists(txt_path):
262
+ if create:
263
+ self.to_txt(txt_path)
264
+ else:
265
+ raise FileNotFoundError(f"文件不存在: {txt_path}")
266
+
236
267
  with open(txt_path, 'r', encoding='utf-8') as f:
237
268
  lines = f.readlines()
238
269
  matrix, row_name, col_name = strs2matrix(lines)
@@ -297,6 +328,51 @@ class B_Table2d:
297
328
  def to_str(self):
298
329
  return '\n'.join(self.to_strs())
299
330
 
331
+ def to_ini(self, path):
332
+ '''
333
+ 输出为ini格式
334
+ :param path:
335
+ :return:
336
+ '''
337
+ if self.is_changed:
338
+ self.__dict2matrix()
339
+
340
+ groups = self.matrix2d.get_rows()[1:]
341
+ keys = self.matrix2d.get_cols()[1:]
342
+ with open(path, 'w', encoding='utf-8') as f:
343
+ for i, group in enumerate(groups):
344
+ f.write(f"[{group}]\n")
345
+ for j, key in enumerate(keys):
346
+ value = self.matrix2d.get_by_index(i+1, j+1)
347
+ f.write(f"{key} = {value}\n")
348
+ f.write("\n")
349
+
350
+ def from_ini(self, path):
351
+ '''
352
+ 输入为ini格式
353
+ :param path:
354
+ :return:
355
+ '''
356
+ with open(path, 'r', encoding='utf-8') as f:
357
+ lines = f.readlines()
358
+
359
+ self.dict2d = Dict2d()
360
+
361
+ group = None
362
+ for line in lines:
363
+ line = line.strip()
364
+ if line.startswith('[') and line.endswith(']'):
365
+ group = line[1:-1]
366
+ elif '=' in line:
367
+ key, value = line.split('=')
368
+ key = key.strip()
369
+ value = value.strip()
370
+ if value == 'None':
371
+ value = None
372
+ self[group][key] = value
373
+
374
+ self.__dict2matrix()
375
+
300
376
  def __str__(self):
301
377
  return self.to_str()
302
378
 
byzh_core/__init__.py CHANGED
@@ -2,4 +2,4 @@
2
2
  # class 以"B_"开头
3
3
  # function 以"b_"开头
4
4
 
5
- __version__ = '0.0.2.5'
5
+ __version__ = '0.0.2.6'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: byzh_core
3
- Version: 0.0.2.5
3
+ Version: 0.0.2.6
4
4
  Summary: byzh_core是byzh系列的核心库,包含了一些常用的工具函数和类。
5
5
  Author: byzh_rc
6
6
  License: MIT
@@ -1,11 +1,11 @@
1
1
  byzh_core/B_os.py,sha256=VFhqVrhcCSm3_gQ0NULqmygYSgO2sOqSIYIYNjQQ2QY,2237
2
- byzh_core/__init__.py,sha256=6eKioXUU_fhNgFfYCHNK0i8E-_J5Q_6O81eU60v1a-E,110
2
+ byzh_core/__init__.py,sha256=Nr5HYfsPfCNuPTXhAwoSPvWfb6ePd7BqOucEE1qKOBU,110
3
3
  byzh_core/Barchive/__init__.py,sha256=wUdz646VS0Uhq9lwMkd3YQHCvQhLDqgADoDjFGMqIn0,65
4
4
  byzh_core/Barchive/archive.py,sha256=yIQgef1APUcZdHM_7Pa9rCam-P3PA3pbcSJSaySoUj4,2498
5
5
  byzh_core/Bbasic/__init__.py,sha256=wr7Y7YJINhgpV5X6BT5DaGJKcHUOZYNerCGXoi2Egac,116
6
6
  byzh_core/Bbasic/text_style.py,sha256=JelgL3AgcH607Mr-Bvr4u8Svb0twmNmqwXvOl4hHOSs,3161
7
7
  byzh_core/Bconfig/__init__.py,sha256=7lAp7wNetW0AyJcike7ekdY_8wrQQtFjBsi6684t_lU,54
8
- byzh_core/Bconfig/config.py,sha256=P9C4kAkxKnIFaJCErBXdABfOyWgFgVHpR-i-fiZXCNs,10956
8
+ byzh_core/Bconfig/config.py,sha256=zfURiqwxXrPo4Pei63GaVvTslHnYTgmleCjeaGBR9K8,10952
9
9
  byzh_core/Bmath/__init__.py,sha256=G3AQug6izkEX3UfzO_mqUNJW88ZKlmYb4Q8CAactK4w,105
10
10
  byzh_core/Bmath/divides.py,sha256=dr85IqGSE9NvugQu7az29GLcjRiLjXU_hZTwtNifIXg,1132
11
11
  byzh_core/Bmath/get_norm.py,sha256=y1QsCTo7qhtGTXIxpc6JtamLWloC7ENRuVdNtK5yi58,596
@@ -14,7 +14,7 @@ byzh_core/Bos/__init__.py,sha256=mMa6OugZs8gIfZMj7go_wEHZRe0JRffgiyIKTF5I_uc,88
14
14
  byzh_core/Bos/make.py,sha256=uGmHc96lXChihJs2jGiXJRp3tU_U5DPCo8jcc-aW6d4,663
15
15
  byzh_core/Bos/remove.py,sha256=HuGQlEOz7IZB_c6T9MzR3miRx60IeaBYP-3lp-P20-I,156
16
16
  byzh_core/Btable/__init__.py,sha256=NlQBjp_mvObEUm4y6wXbGipkNM2N3uNIUidaJkTwFsw,62
17
- byzh_core/Btable/auto_table.py,sha256=xEPe47hvoJpOHudWAdr_7pZqrs1W9hvWuJgwhOlPDfo,12378
17
+ byzh_core/Btable/auto_table.py,sha256=nc8RvF86laDnITAzX8sVj3l5tbIGflrsstIbSbGDaAI,14747
18
18
  byzh_core/Btable/obsolete/__init__.py,sha256=wpfHMPD4awPRDJVYlaiGtkkpjq2srWB7d7LrWhoX5R0,161
19
19
  byzh_core/Btable/obsolete/auto_table.py,sha256=nC9eHj_IIGVkS2lmN_1gtOyglLCaGlwdoHzPvNNQDEw,13952
20
20
  byzh_core/Btable/obsolete/row_table.py,sha256=rIX0-Yvb3RnO0RJBkA4m18gux1zYSnEKTy6uQGcWilc,5999
@@ -26,8 +26,8 @@ byzh_core/Btqdm/my_tqdm.py,sha256=myyFo3GgyX_wWfSjMWfSTkcnTECf1tqwpXEFpJkzNtw,28
26
26
  byzh_core/Bwriter/__init__.py,sha256=KSsbCJZ-1j5wOr-ZbTg8K3A8Du73d22DQVLdmq-3CBo,116
27
27
  byzh_core/Bwriter/globalwriter.py,sha256=tSjWxzLylAeZep67n5jbRsjQkXkBKRZLvKXUyGSY92Q,1824
28
28
  byzh_core/Bwriter/writer.py,sha256=px0ZNoSuXS_RbwVnYsBx2lYohyhHACfHM8-HBNEflhU,4006
29
- byzh_core-0.0.2.5.dist-info/LICENSE,sha256=-nRwf0Xga4AX5bsWBXXflpDpgX_U23X06oAMcdf0dSY,1089
30
- byzh_core-0.0.2.5.dist-info/METADATA,sha256=_bY5y1V5XcgMQReiBrMErgm0mI_fp7HyzqHmXxx94N8,371
31
- byzh_core-0.0.2.5.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
32
- byzh_core-0.0.2.5.dist-info/top_level.txt,sha256=Xv-pzvl6kPdIbi5UehQcUdGhLtb8-4WhS5dRK1LINwM,10
33
- byzh_core-0.0.2.5.dist-info/RECORD,,
29
+ byzh_core-0.0.2.6.dist-info/LICENSE,sha256=-nRwf0Xga4AX5bsWBXXflpDpgX_U23X06oAMcdf0dSY,1089
30
+ byzh_core-0.0.2.6.dist-info/METADATA,sha256=ira6o6p4YHEW2I2AhxwV0snAJlYbkrVa44hacgpkGmA,371
31
+ byzh_core-0.0.2.6.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
32
+ byzh_core-0.0.2.6.dist-info/top_level.txt,sha256=Xv-pzvl6kPdIbi5UehQcUdGhLtb8-4WhS5dRK1LINwM,10
33
+ byzh_core-0.0.2.6.dist-info/RECORD,,