It doesn't seem that it's possible to use a string as the name of a variable. I basically want the program to understand that the thing inside the quote marks is the name of an object I want to reference. I want to do something like this:
str = "modname"
import var(str)
var() is a fictional function. I'm using it in the way one might use str() or int(). I imagine you might ask "Why?" It's so I can do something like this:
class player:
__init___():
attributes = [ "hp", "attack", "defense" ]
for x in range( 0, len(self.attributes) ]:
self.var(attributes[x]) = var( attributes[x] + "()" )
(Assuming you've already done something like from stats import *
). But the real payoff would be the ability to do something like this:
for x in range( 0, len(self.attributes) ):
self.var(attributes[x]).modAttr(-5)
print self.var(attributes[x]).magnitude
Is this possible? Is it completely absurd to want to do this? Or is there a different, more canon way to perform such a task?