代码来源:
https://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/001386820066616a77f826d876b46b9ac34cb5f34374f7a000
f = open('/Users/michael/test.txt', 'r')
>>> f.read()
'Hello, world!'
>>> f.close()
要点:
1.读取文件路径的斜杠是/
2.'r'
为了能将文件正确编码,需要import io
实例:a=io.open('D:/1.txt','r',encoding='utf-8').read()