私は属性「健康」を持つクラス(ボット)を持っています。このクラスには多くのパラメーターがあり、ユーザーに多くのパラメーターを入力してもらいたいので、{param:explanation} の dict をループして、パラメーターごとに設定する値を入力することにしました。
attr_array = ["health",...]
attr_dict = {}
attr_dict["health"] = "your bot's health"
...
for attr in attr_array:
tmp_attr = input(attr + attr_dict[attr] + ": ")
setattr(tmp_bot, attr_dict[attr], tmp_attr)
print attr, getattr(tmp_bot, attr_dict[attr])
print str(tmp_bot.health) + " hp"
したがって、print attr, getattr... 行は (サンプル) "health 50" を返しますが、print str 行は "0 hp" を返します。
これが起こる理由はありますか?