TypeError: str decoding is not supported

I am trying to make a characteristic randomizer attribute for my nephew game, and I am trying to write the attributes to an external file so that he can use them later. when I try to write to a file, it encounters an error

speedE = str('Speed -', str(speed))
TypeError: decoding str is not supported

my code adds the computed attribute to the attribute name. I.E. ('Strength -', strengthE) my code ...

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))
char2.write(speedE2)
strengthE2 = str('Strength -', str(strength))
char2.write(strengthE2)
print(char1)
char2.close()

im brand new to write to external files and that is not too good aha. my nephew and I would be very grateful if you could help, thanks

+4
source share
1 answer

Not sure what you expect str('Speed -', str(speed)).

What you want is the concat line:

speedE2 = 'Speed -' + str(speed)
# replace other lines also

cast:

speedE2 = 'Speed -{}'.format(speed)
+3

Source: https://habr.com/ru/post/1658632/


All Articles