解决办法如下: 使用自带的codecs库 import codecs with open('learning_python.txt',encoding='utf-8') as file_object: contents=file_object.read().replace('Python','C#') print(contents)