seewo 0.0.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.
- seewo/__init__.py +93 -0
- seewo-0.0.1.dist-info/METADATA +11 -0
- seewo-0.0.1.dist-info/RECORD +5 -0
- seewo-0.0.1.dist-info/WHEEL +5 -0
- seewo-0.0.1.dist-info/top_level.txt +1 -0
seewo/__init__.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
def kong():
|
|
4
|
+
"""打印空行"""
|
|
5
|
+
print()
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def xr(A, B):
|
|
9
|
+
"""追加写入B到文件A;文件空则直接写,非空先换行再写"""
|
|
10
|
+
folder = os.path.dirname(A)
|
|
11
|
+
if folder:
|
|
12
|
+
os.makedirs(folder, exist_ok=True)
|
|
13
|
+
|
|
14
|
+
# ✅第一步:单独用r模式读取原有内容,不要用a模式句柄read
|
|
15
|
+
if os.path.exists(A):
|
|
16
|
+
with open(A, 'r', encoding="utf-8") as fr:
|
|
17
|
+
file_data = fr.read().strip()
|
|
18
|
+
else:
|
|
19
|
+
file_data = ""
|
|
20
|
+
|
|
21
|
+
# ✅第二步:a模式打开,执行追加
|
|
22
|
+
with open(A, 'a', encoding="utf-8") as fw:
|
|
23
|
+
if file_data == '':
|
|
24
|
+
fw.write(f"{B}")
|
|
25
|
+
else:
|
|
26
|
+
fw.write(f"\n{B}")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def xr_many(A, lines):
|
|
30
|
+
"""追加多行,lines是列表"""
|
|
31
|
+
for line in lines:
|
|
32
|
+
xr(A, line)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def dq(A):
|
|
36
|
+
"""读取文件全部内容,返回字符串"""
|
|
37
|
+
if not os.path.exists(A):
|
|
38
|
+
return ""
|
|
39
|
+
f = open(A, 'r', encoding="utf-8")
|
|
40
|
+
file_data = f.read().strip()
|
|
41
|
+
f.close()
|
|
42
|
+
return file_data
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def dq_lines(A):
|
|
46
|
+
"""读取文件,返回每行组成列表"""
|
|
47
|
+
if not os.path.exists(A):
|
|
48
|
+
return []
|
|
49
|
+
with open(A, "r", encoding="utf-8") as f:
|
|
50
|
+
return [i.rstrip("\n") for i in f]
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def clear_file(A):
|
|
54
|
+
"""清空文件内容"""
|
|
55
|
+
if os.path.exists(A):
|
|
56
|
+
open(A, "w", encoding="utf-8").close()
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def file_exists(A):
|
|
60
|
+
"""判断文件是否存在,返回True/False"""
|
|
61
|
+
return os.path.isfile(A)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def rm_file(A):
|
|
65
|
+
"""删除文件"""
|
|
66
|
+
if os.path.exists(A):
|
|
67
|
+
os.remove(A)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def sss():
|
|
71
|
+
"""交互读写菜单"""
|
|
72
|
+
s_flag = True
|
|
73
|
+
while s_flag:
|
|
74
|
+
print("\n==== seewo 文件工具 ====")
|
|
75
|
+
print('1、写入。')
|
|
76
|
+
print('2、读取。')
|
|
77
|
+
print('3、清空文件。')
|
|
78
|
+
print('bb、退出')
|
|
79
|
+
x = input('你的选择:')
|
|
80
|
+
if x == '1':
|
|
81
|
+
a = input('写入的内容:')
|
|
82
|
+
xr('xr.txt', a)
|
|
83
|
+
print("已追加写入!")
|
|
84
|
+
elif x == '2':
|
|
85
|
+
res = dq("xr.txt")
|
|
86
|
+
print(f'内容:[{res}]')
|
|
87
|
+
elif x == "3":
|
|
88
|
+
clear_file("xr.txt")
|
|
89
|
+
print("文件已清空")
|
|
90
|
+
elif x == 'bb':
|
|
91
|
+
s_flag = False
|
|
92
|
+
else:
|
|
93
|
+
print('输入无效!')
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
seewo/__init__.py,sha256=gGGtOBArFRr1Eg5dOK2OoFDtSsE_syVW9HdnuR-xMBg,2336
|
|
2
|
+
seewo-0.0.1.dist-info/METADATA,sha256=e3HWWcvAJKMrqz6YLXY9_Tvm5xbi_8vXzmHq9gc0ZuU,297
|
|
3
|
+
seewo-0.0.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
4
|
+
seewo-0.0.1.dist-info/top_level.txt,sha256=yLSTmnKpwhaQXi5Wj8GjhlT80cBAdXRIa9jvdZo1afk,6
|
|
5
|
+
seewo-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
seewo
|