小编Lom*_*ore的帖子

TypeError:不支持解码str

我试图为我的侄子棋盘游戏制作属性特征随机数,我试图将属性写入外部文件,以便以后可以使用它们.当我试图写入文件时,它会出现错误

speedE = str('Speed -', str(speed))
TypeError: decoding str is not supported
Run Code Online (Sandbox Code Playgroud)

我的代码是将计算出的属性添加到属性的名称中.IE('Strength - ',strengthE)我的代码是......

import random

char1 = open('Character1.txt', 'w')
strength = 10
strength += int(random.randint(1, 12) / random.randint(1,4))
speed = 10
speed += int(random.randint(1, 12) / random.randint(1,4))
speedE = str('Speed -', str(speed))
char1.write(speedE)
strengthE = str('Strength -', str(strength))
char1.write(strengthE)
print(char1)
char1.close()

char2 = open('Character2.txt', 'w')
strength2 = 10
strength2 += int(random.randint(1, 12) / random.randint(1,4))
speed2 = 10
speed += int(random.randint(1, 12) / random.randint(1,4))
speedE2 = str('Speed -', str(speed)) …
Run Code Online (Sandbox Code Playgroud)

python string decoding typeerror notsupportedexception

8
推荐指数
1
解决办法
3万
查看次数