MCPcopy Create free account
hub / github.com/a943512/PyAibote / WriteReadFile

Class WriteReadFile

PyAibote/Tool/WriteReadFileFunc.py:10–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8import traceback
9
10class WriteReadFile(LoggerRecord):
11 def WriteFile(self, path, data) -> bool:
12 """
13 写入文件
14 WriteFile
15
16 path: 需要写入的文件路径
17 data: 需要写入的数据
18 return: 成功返回True or 失败返回False
19
20 path: the file path that needs to be written
21 data: data to be written
22 return: Returns True or success or False on failure
23 """
24
25 try:
26 with open(path,'w',encoding='UTF-8') as w:
27 w.write(data)
28 return True
29 except Exception as e:
30 WriteReadFile.Custom_Write_logger(self,"",f"{os.getcwd()}/AiBotRunLOG/{time.strftime(r'%Y-%m-%d',time.localtime(time.time()))}/","SysModeError.log",False,"error",f"{traceback.format_exc()}")
31 return False
32
33 def ReadFile(self,path) -> str or bool:
34 """
35 读取文件
36 ReadFile
37
38 path: 需要读取的文件路径
39 return: 成功返回文件数据, 失败返回False
40
41 path: the file path to be read
42 return: file data is returned successfully, and False is returned if it fails
43 """
44
45 try:
46 with open(path,'r',encoding='UTF-8') as r:
47 Data = r.read()
48 return Data
49 except Exception as e:
50 WriteReadFile.Custom_Write_logger(self,"",f"{os.getcwd()}/AiBotRunLOG/{time.strftime(r'%Y-%m-%d',time.localtime(time.time()))}/","SysModeError.log",False,"error",f"{traceback.format_exc()}")
51 return False
52
53 def WriteFileAddTo(self,path,data) -> bool:
54 """
55 追加写入文件
56 Additional write file
57
58 path: 需要追加写入的文件路径
59 data: 需要追加写入的数据
60 return: 成功返回True, 失败返回False
61
62 path: the file path that needs additional writing
63 data: data that needs to be written additionally
64 return: file data is returned successfully, and False is returned if it fails
65 """
66
67 try:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected