1、Python读取文件

# 1、打开文件
file = open("ReadMe")
# 2、读取文件类容
text = file.read()
print(text)
# 3、关闭文件
file.close()

2、出现错误为

Traceback (most recent call last):
  File "F:/学习区/Python/13_文件/hm_01_读取文件内容.py", line 4, in <module>
    text = file.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 41: illegal multibyte sequence

3、修改文件打开时编码格式,

# 1、打开文件
file = open("ReadMe",encoding="UTF-8")

4、解决后

hello python
错误总会被慢慢解决

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-13
  • 2021-09-30
  • 2021-09-12
  • 2022-12-23
猜你喜欢
  • 2022-01-21
  • 2022-12-23
  • 2022-12-23
  • 2021-06-23
  • 2022-12-23
  • 2021-11-07
  • 2021-06-02
相关资源
相似解决方案