byzh-core 0.0.8.0__py3-none-any.whl → 0.0.9.0__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.
@@ -15,39 +15,39 @@ class B_Record2d:
15
15
  elif mode == "a":
16
16
  self.__read()
17
17
 
18
- def write(self, row, col, value):
19
- row, col, value = str(row), str(col), str(value)
18
+ # 支持 recorder[row, col] 访问
19
+ def __getitem__(self, key):
20
+ row, col = key
21
+ row, col = str(row), str(col)
22
+ return self.data.loc[row, col]
20
23
 
21
- # 如果行不存在,pandas 会自动创建
22
- # 如果列不存在,pandas 也会自动扩展
24
+ # 支持 recorder[row, col] = value
25
+ def __setitem__(self, key, value):
26
+ row, col = key
27
+ row, col, value = str(row), str(col), str(value)
23
28
  self.data.loc[row, col] = value
24
-
25
- # 保存
26
29
  self.__save()
27
30
 
28
- def get(self, row, col) -> Any:
29
- row, col = str(row), str(col)
30
- result = self.data.loc[row, col]
31
- return result
31
+ def write(self, row, col, value):
32
+ self[row, col] = value
33
+
34
+ def get(self, row, col):
35
+ return self[row, col]
36
+
32
37
  def get_str(self, row, col) -> str:
33
- row, col = str(row), str(col)
34
- result = self.data.loc[row, col]
35
- return str(result)
38
+ return str(self[row, col])
36
39
 
37
40
  def get_int(self, row, col) -> int:
38
- row, col = str(row), str(col)
39
- result = self.data.loc[row, col]
40
- return int(result)
41
+ return int(self[row, col])
42
+
41
43
  def get_float(self, row, col) -> float:
42
- row, col = str(row), str(col)
43
- result = self.data.loc[row, col]
44
- return float(result)
44
+ return float(self[row, col])
45
+
45
46
  def get_bool(self, row, col) -> bool:
46
- row, col = str(row), str(col)
47
- result = self.data.loc[row, col]
48
- if result == "True" or result == "true" or result == "1":
47
+ result = self[row, col]
48
+ if result in ("True", "true", "1"):
49
49
  return True
50
- elif result == "False" or result == "false" or result == "0":
50
+ elif result in ("False", "false", "0"):
51
51
  return False
52
52
  else:
53
53
  raise ValueError(f"无法转换为布尔值 -> {result}")
@@ -55,9 +55,7 @@ class B_Record2d:
55
55
  def __read(self):
56
56
  try:
57
57
  self.data = pd.read_csv(self.csv_path, index_col=0)
58
- except FileNotFoundError:
59
- self.data = pd.DataFrame()
60
- except pd.errors.EmptyDataError:
58
+ except (FileNotFoundError, pd.errors.EmptyDataError):
61
59
  self.data = pd.DataFrame()
62
60
 
63
61
  def __save(self, csv_path=None):
@@ -68,19 +66,20 @@ class B_Record2d:
68
66
  def __str__(self):
69
67
  return str(self.data)
70
68
 
69
+
71
70
  if __name__ == '__main__':
72
71
  csv_file = "test_data.csv"
73
72
 
74
73
  recorder = B_Record2d(csv_file, mode="w")
75
74
 
76
- # 写入一些单元格
77
- recorder.write("awa", "OvO", 10)
78
- recorder.write("awa", "TwT", 20)
79
- recorder.write("qwq", "OvO", 30)
80
- recorder.write("qwq", "TwT", 40)
75
+ # 用索引方式赋值
76
+ recorder["awa", "OvO"] = 10
77
+ recorder["awa", "TwT"] = 20
78
+ recorder["qwq", "OvO"] = 30
79
+ recorder["qwq", "TwT"] = 40
81
80
 
82
81
  print("当前内容:")
83
82
  print(recorder)
84
83
 
85
- recorder = B_Record2d(csv_file, mode="a")
86
- print(recorder)
84
+ # 用索引方式读取
85
+ print("awa, OvO =", recorder["awa", "OvO"])
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: byzh-core
3
- Version: 0.0.8.0
4
- Summary: byzh_core是byzh系列的核心库,包含了一些常用的工具函数和类。
3
+ Version: 0.0.9.0
4
+ Summary: byzh-core是byzh系列的核心库,包含了一些常用的工具函数和类。
5
5
  Author: byzh_rc
6
6
  License: MIT
7
7
  Description-Content-Type: text/markdown
@@ -4,7 +4,7 @@ byzh/core/Barchive/__init__.py,sha256=wUdz646VS0Uhq9lwMkd3YQHCvQhLDqgADoDjFGMqIn
4
4
  byzh/core/Barchive/archive.py,sha256=S1hy3qYFEZr5RRmx_Mnq1s2IMUEw973ny1rKSL7J_a0,6721
5
5
  byzh/core/Brecorder/__init__.py,sha256=rYlgYIhr_AcPuGkZRCitbi2_hZYyoERk4XIZ14CU1dk,108
6
6
  byzh/core/Brecorder/record1d.py,sha256=0iPVzX5-x-iX02HMZSq0goekNp-_g2W3uS0ZaHlAEkY,2037
7
- byzh/core/Brecorder/record2d.py,sha256=SIFDZVGEjizYBbp0QJl7ILCAPHdG3wcVmCvmJ3Kr2w8,2585
7
+ byzh/core/Brecorder/record2d.py,sha256=vVCJ5iJ-EFw4ACdKIGfUdLNlMhQsgTbZtqp-EBO4h_M,2320
8
8
  byzh/core/Btable/__init__.py,sha256=NlQBjp_mvObEUm4y6wXbGipkNM2N3uNIUidaJkTwFsw,62
9
9
  byzh/core/Btable/auto_table.py,sha256=avMeRWydw9L8s3fU0-BSl8a2dCyreIUzW--csm5eR0g,14734
10
10
  byzh/core/Bterminal/__init__.py,sha256=azRLD-kY8Tv2c3llHRBrEJIdVgYw6hAoLgzJeA4PvE0,142
@@ -18,9 +18,9 @@ byzh/core/Butils/text_style.py,sha256=34u2-Rsur63iNQ0m7tHxpFWqnQZWybSxBx7vnhOhqD
18
18
  byzh/core/Butils/timer.py,sha256=OLxbWWRauYjp1KwavACjoyrqrCciUiIG2ae7qgtZrVA,511
19
19
  byzh/core/Bwriter/__init__.py,sha256=QcHzKs0305Pr78ZvZgcC_4miSYZh8jJQDt5TD0GIeEg,82
20
20
  byzh/core/Bwriter/writer.py,sha256=ss9EWo-l7czBUlY7Fu0buvQgO5fRspYKtC2X6eaRa0c,3213
21
- byzh_core-0.0.8.0.dist-info/LICENSE,sha256=-nRwf0Xga4AX5bsWBXXflpDpgX_U23X06oAMcdf0dSY,1089
22
- byzh_core-0.0.8.0.dist-info/METADATA,sha256=R_g0yzV3USWUfVBtvA_G0eQO2uHS8jHbj1GholsRNqQ,371
23
- byzh_core-0.0.8.0.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
24
- byzh_core-0.0.8.0.dist-info/entry_points.txt,sha256=qoN3Uvulj0BcOQVDqsFqP2dBVQzG1QrUtC5wFsghSLo,51
25
- byzh_core-0.0.8.0.dist-info/top_level.txt,sha256=tmaFVY8uApe6apOETSOgwz-4v5Mj4uxgRT8yNnDNZNA,5
26
- byzh_core-0.0.8.0.dist-info/RECORD,,
21
+ byzh_core-0.0.9.0.dist-info/LICENSE,sha256=-nRwf0Xga4AX5bsWBXXflpDpgX_U23X06oAMcdf0dSY,1089
22
+ byzh_core-0.0.9.0.dist-info/METADATA,sha256=96-JretCMR_wj3-RuS61cG2edQTRO1pT20FD8P1DpNw,371
23
+ byzh_core-0.0.9.0.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
24
+ byzh_core-0.0.9.0.dist-info/entry_points.txt,sha256=qoN3Uvulj0BcOQVDqsFqP2dBVQzG1QrUtC5wFsghSLo,51
25
+ byzh_core-0.0.9.0.dist-info/top_level.txt,sha256=tmaFVY8uApe6apOETSOgwz-4v5Mj4uxgRT8yNnDNZNA,5
26
+ byzh_core-0.0.9.0.dist-info/RECORD,,