读写文件语法
read()
#读取文件内容
with open('/letter.txt','r',encoding = 'UTF-8') as f:
content = f.read()
#以字符串的形式读取文件内容,将文件内容赋值给变量content
readlines()
#以列表的方式读取文件内容
with open('/letter.txt','r',encoding = 'UTF-8') as f:
content = f.readlines()
#以列表的形式读取文件内容,将文件内容赋值给变量content
write()
#清空文件内容,并写入字符串入内容
with open('/letter.txt','r',encoding = 'UTF-8') as f:
f.write('python')
writelines()
#清空文件内容,以列表的方式写入
with open('/letter.txt','r',encoding = 'UTF-8') as f:
f.writelines('python')