1、文件操作
1.1 读文件
- 读文本文件
##打开文件
- 路径:
相对路径:‘info.txt’
绝对路径: ‘/Users/pengfei/day09/info.txt’
# 打开文件
file_object = open('info.txt',mode = 'rb')
# 读取文件
data = file_object.read()
# 关闭文件
file_object.close()
text = data.decode('utf-8')
print(text)
- 读图片等非文本内容文件
file_object = open('al.png',mode = 'rb')
data = file_object.read()
file_object.close()