模块中存在问题

nc1teljy  于 2021-09-08  发布在  Java
关注(0)|答案(1)|浏览(404)

我在制造一个不和谐的机器人这是代码和错误

f = open("rules.txt","r")
rules = f.readlines()

错误:

Traceback (most recent call last):
  File "C:\Users\Windows10\OneDrive\Desktop\YourBot\bot.py", line 8, in <module>
    rules = f.readlines()
  File "C:\Users\Windows10\AppData\Local\Programs\Python\Python39\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 7: character maps to <undefined>

请帮帮我。。

pkbketx9

pkbketx91#

请先尝试:

f = open('rules.txt', 'r', encoding='utf8')
rules = f.readlines()

第二:

f = open('rules.txt', 'r', errors = 'ignore')
rules = f.readlines()

相关问题