python解码问题

读文件时

UnicodeDecodeError: 'gbk' codec can't decode byte 0x90 in position 2: illegal multibyte sequence

加入encoding='UTF-8'解码后又显示

TypeError: test() got an unexpected keyword argument 'encoding'

望采纳,有问题可以交流


读取文件时遇到UnicodeDecodeError,是因为文件的编码格式与Python的默认编码格式不一致,你可以在读文件时指定编码

with open('file.txt', encoding='UTF-8') as f:
    data = f.read()

你的test函数报错,需要看一下test完整的代码。