def getVital(ch, vital):
return eval("ch.aux('vitals_aux')." + vital + "['cur']")
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class A(object):
… def __init__(self):
… self.foo = 'bar'
… self.vitals = {'str' : 10, 'int' : 11, 'dex' : 14}
…
>>> a = A()
>>> a.__dict__
{'foo': 'bar', 'vitals': {'int': 11, 'dex': 14, 'str': 10}}
>>> a.__dict__['vitals']['str']
10
>>>
Current function:
Essentially, I want the above function but in this form:
However using that returns an error, as there's no "vital" dictionary stored in the character's auxiliary data (a NakedMUD thing).
I'm almost certain this is a result of me using the language wrong, so I was wondering if there's something I can use to "expand"
and replace that single instance of "vital" with whatever is stored in the variable "vital".
Thanks!