byzh-core 0.0.8.0__py3-none-any.whl → 0.0.9.1__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.
- byzh/core/Brecorder/record1d.py +2 -1
- byzh/core/Brecorder/record2d.py +34 -35
- {byzh_core-0.0.8.0.dist-info → byzh_core-0.0.9.1.dist-info}/METADATA +2 -2
- {byzh_core-0.0.8.0.dist-info → byzh_core-0.0.9.1.dist-info}/RECORD +8 -8
- {byzh_core-0.0.8.0.dist-info → byzh_core-0.0.9.1.dist-info}/LICENSE +0 -0
- {byzh_core-0.0.8.0.dist-info → byzh_core-0.0.9.1.dist-info}/WHEEL +0 -0
- {byzh_core-0.0.8.0.dist-info → byzh_core-0.0.9.1.dist-info}/entry_points.txt +0 -0
- {byzh_core-0.0.8.0.dist-info → byzh_core-0.0.9.1.dist-info}/top_level.txt +0 -0
byzh/core/Brecorder/record1d.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import pandas as pd
|
2
|
+
from typing import Literal
|
2
3
|
|
3
4
|
from .. import B_os
|
4
5
|
|
@@ -10,7 +11,7 @@ class B_Record1d:
|
|
10
11
|
recorder.write(name="Bob", age=30, city="Beijing")
|
11
12
|
recorder.write(name="Charlie", age=22, city="Shenzhen")
|
12
13
|
'''
|
13
|
-
def __init__(self, csv_path, mode
|
14
|
+
def __init__(self, csv_path, mode:Literal["w", "a"]="w"):
|
14
15
|
self.csv_path = csv_path
|
15
16
|
|
16
17
|
B_os.makedirs(csv_path)
|
byzh/core/Brecorder/record2d.py
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
import pandas as pd
|
2
|
-
from typing import
|
2
|
+
from typing import Literal
|
3
3
|
|
4
4
|
from .. import B_os
|
5
5
|
|
6
6
|
class B_Record2d:
|
7
|
-
def __init__(self, csv_path, mode
|
7
|
+
def __init__(self, csv_path, mode:Literal["w", "a"]="w"):
|
8
8
|
self.csv_path = csv_path
|
9
9
|
|
10
10
|
B_os.makedirs(csv_path)
|
@@ -15,39 +15,39 @@ class B_Record2d:
|
|
15
15
|
elif mode == "a":
|
16
16
|
self.__read()
|
17
17
|
|
18
|
-
|
19
|
-
|
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
|
-
|
22
|
-
|
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
|
29
|
-
row, col =
|
30
|
-
|
31
|
-
|
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
|
-
|
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
|
-
|
39
|
-
|
40
|
-
return int(result)
|
41
|
+
return int(self[row, col])
|
42
|
+
|
41
43
|
def get_float(self, row, col) -> float:
|
42
|
-
|
43
|
-
|
44
|
-
return float(result)
|
44
|
+
return float(self[row, col])
|
45
|
+
|
45
46
|
def get_bool(self, row, col) -> bool:
|
46
|
-
|
47
|
-
result
|
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
|
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
|
78
|
-
recorder
|
79
|
-
recorder
|
80
|
-
recorder
|
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
|
-
|
86
|
-
print(recorder)
|
84
|
+
# 用索引方式读取
|
85
|
+
print("awa, OvO =", recorder["awa", "OvO"])
|
@@ -3,8 +3,8 @@ byzh/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
3
|
byzh/core/Barchive/__init__.py,sha256=wUdz646VS0Uhq9lwMkd3YQHCvQhLDqgADoDjFGMqIn0,65
|
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
|
-
byzh/core/Brecorder/record1d.py,sha256=
|
7
|
-
byzh/core/Brecorder/record2d.py,sha256=
|
6
|
+
byzh/core/Brecorder/record1d.py,sha256=P7y4Gbc0zYcRsZBT4CeYgv35k0tU4h3ED-3H8RQ6cuU,2083
|
7
|
+
byzh/core/Brecorder/record2d.py,sha256=pR2qyoG_Wo40RN9ygB4z-wZfBmCW25EYjGHz3de6lLM,2342
|
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.
|
22
|
-
byzh_core-0.0.
|
23
|
-
byzh_core-0.0.
|
24
|
-
byzh_core-0.0.
|
25
|
-
byzh_core-0.0.
|
26
|
-
byzh_core-0.0.
|
21
|
+
byzh_core-0.0.9.1.dist-info/LICENSE,sha256=-nRwf0Xga4AX5bsWBXXflpDpgX_U23X06oAMcdf0dSY,1089
|
22
|
+
byzh_core-0.0.9.1.dist-info/METADATA,sha256=g6HCDJ6JSj8wezcuKeSA5LGHPWswr0WKyTEXh5yHgDQ,371
|
23
|
+
byzh_core-0.0.9.1.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
|
24
|
+
byzh_core-0.0.9.1.dist-info/entry_points.txt,sha256=qoN3Uvulj0BcOQVDqsFqP2dBVQzG1QrUtC5wFsghSLo,51
|
25
|
+
byzh_core-0.0.9.1.dist-info/top_level.txt,sha256=tmaFVY8uApe6apOETSOgwz-4v5Mj4uxgRT8yNnDNZNA,5
|
26
|
+
byzh_core-0.0.9.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|