I am trying to turn a string into a variable name. I already have the variable declared and want to use it to declare another variable with it. For example I have a class named player
and want to change the armor the player is wearing with this code.
gt = gettext("playerarmor", 1, 1)
for i in armorlist:
if i == gt:
player.armor = i
But the gettext
function here:
def gettext(header, move, count):
with open('dictionary.txt', 'r') as f:
f = f.read()
lines = f.split("\n")
for i, line in enumerate(lines):
if header in line:
word = []
for l in range(0, count):
newindex = i + move
word.append(lines[newindex+l])
return "\n".join(word)
only returns a string which is rags
and is already declared. How can I make this happen?