Python 文件操作

Posted on 2018-12-05 21:11  缥缈映苍穹  阅读(111)  评论(0)    收藏  举报
# r:read 只读
f = open("例子.txt", mode = "r", encoding = "utf-8")
# 读取内容
content = f.read() # 全部都读取出来
print(content)

# 坑:
c2 = f.read() #读取不到内容, 因为上面已经读取完毕,光标在末尾
print("c2",c2)

# 良好习惯
f.close() # 关闭连接