这里介绍文件存放在不同路径下,读取文件的方法:
1.文件存放在python路径下,代码如下:
//
with open('from.txt',encoding='utf-8') as f:
file = f.read()
file = str(file)
print(file)
2.文件存放在桌面上,代码如下:
//
path = 'C://Users/Tracy/Desktop/from.txt'
with open(path,encoding='utf-8') as a:
file = a.read()
print(file)