python之文件读取
# 方法1
fd = open("D:/project/python_project/com/baidu/uos/demo.text", "r", encoding="utf-8")
print(fd.read())
fd.close()
# 等价于方法2
try:
fd = open("D:/project/python_project/com/baidu/uos/demo.text", "r", encoding="utf-8")
print(fd.read())
finally:
if fd:
fd.close()
# 等价于方法3
with open("D:/project/python_project/com/baidu/uos/demo.text", "r", encoding="utf-8") as fd:
print(fd.read())
posted on 2020-09-07 17:08 Indian_Mysore 阅读(59) 评论(0) 收藏 举报
浙公网安备 33010602011771号