Python提示_io.TextIOWrapper name='name.txt' mode='r' encoding='UTF-8'解决方法 Python

原代码

 file2 = open('name.txt','r')
 print(file2)
 file2.close()

输出后出错

<_io.TextIOWrapper name='name.txt' mode='r' encoding='UTF-8'>

修改后的代码

file2 = open('name.txt','r',encoding='UTF-8')
 print(file2.read())
 file2.close()             

可成功打印出想要的文本

你可能感兴趣的:(Python)