byzh-core 0.0.2.4__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
@@ -46,11 +46,9 @@ def strs2matrix(str_lst):
46
46
 
47
47
  matrix = []
48
48
  for i in range(row_cnt):
49
- row = []
49
+ row = str_lst[i].split('|')[1:-1]
50
50
  for j in range(col_cnt):
51
- start = indexes[j] + 1
52
- end = indexes[j+1]
53
- row.append(str_lst[i][start:end].strip())
51
+ row[j] = row[j].strip()
54
52
  matrix.append(row)
55
53
 
56
54
  row_name, col_name = matrix[0][0].split(' \\ ')
@@ -62,7 +60,7 @@ class Matrix2d:
62
60
  def __init__(self, row_name='x', col_name='y'):
63
61
  self.row_name = row_name
64
62
  self.col_name = col_name
65
- self.matrix = [[row_name + ' | ' + col_name]]
63
+ self.matrix = [[row_name + ' \\ ' + col_name]]
66
64
 
67
65
  def get_rows(self): # 包含left_upper
68
66
  if self.matrix == [[]]:
@@ -153,9 +151,14 @@ class Dict1d:
153
151
 
154
152
  def __getitem__(self, key):
155
153
  key = str(key)
156
- return self.dict[key]
154
+ try:
155
+ return self.dict[key]
156
+ except KeyError:
157
+ return None
157
158
  def __setitem__(self, key, value): # 用于最底层赋值
158
159
  key, value = str(key), str(value)
160
+ if value == 'None':
161
+ value = ' '
159
162
  self.dict[key] = value
160
163
  def set(self, key, value): # 用于非底层赋值(防止把子dict变为str)
161
164
  key = str(key)
@@ -216,6 +219,26 @@ class B_Table2d:
216
219
  # 判断是否改变
217
220
  self.is_changed = False
218
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
+
219
242
  def __getitem__(self, row):
220
243
  self.is_changed = True
221
244
 
@@ -228,13 +251,19 @@ class B_Table2d:
228
251
  row = str(row)
229
252
  self.dict2d[row] = new_dict
230
253
 
231
- 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):
232
255
  '''
233
-
234
256
  :param txt_path:
257
+ :param create: 如果文件不存在,则创建
235
258
  :param use_txt_name: 默认使用init时的row_name和col_name
236
259
  :return:
237
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
+
238
267
  with open(txt_path, 'r', encoding='utf-8') as f:
239
268
  lines = f.readlines()
240
269
  matrix, row_name, col_name = strs2matrix(lines)
@@ -299,6 +328,51 @@ class B_Table2d:
299
328
  def to_str(self):
300
329
  return '\n'.join(self.to_strs())
301
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
+
302
376
  def __str__(self):
303
377
  return self.to_str()
304
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.4'
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.4
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=n0Ti6pJ4Uy4_BXQs6bS3Bm1uD3XWElbAhaRdE5r_X7w,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=xc8qcgdmLF2dAihuH21L2N7ZQ-LHuzEZOF2xRIJFWA4,12439
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.4.dist-info/LICENSE,sha256=-nRwf0Xga4AX5bsWBXXflpDpgX_U23X06oAMcdf0dSY,1089
30
- byzh_core-0.0.2.4.dist-info/METADATA,sha256=nkEXXZAcGSzNRChClkbvuHruYDRFZrZ8VNZOopHmV1s,371
31
- byzh_core-0.0.2.4.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
32
- byzh_core-0.0.2.4.dist-info/top_level.txt,sha256=Xv-pzvl6kPdIbi5UehQcUdGhLtb8-4WhS5dRK1LINwM,10
33
- byzh_core-0.0.2.4.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,,