# mode有r, rb, r+, r+b 四种模式
# encode 根据文件编码来定
# 句柄有read(), read(n), readline(), readlines() 操作模式
f1 = open("xxx.txt", mode="r", encode="utf-8")
f1.read()
f1.close()
with open("xxx.txt") as f1:
f1.read()
# mode有w, wb, w+, w+b 四种模式
f = open("xxx.txt", mode="w", encoding="utf-8")
f.write("写入")
f.close()
# mode有a, ab, a+, a+b四种模式
f = open("xxx.txt", mode="a", encoding="utf-8")
f.write("追加")
f.close()
f.tell() # 确定光标位置
f.seek(int) # 设置光标位置
f.flush() # 将内存数据写入硬盘
l1 = []
with open('a1.txt', 'r', encoding='utf-8') as fr:
for text in fr.readlines():
if text.split():
l1.append(text.split())