0
は私が唯一DjangoのPythonのevalの
if myUser.profile.get_setting_c == True :
# below does not work but you get the idea, how
if myUser.profile.eval('get_setting_c') == True :
は私が唯一DjangoのPythonのevalの
if myUser.profile.get_setting_c == True :
# below does not work but you get the idea, how
if myUser.profile.eval('get_setting_c') == True :
動的にする必要があります一つの小さな変化が機能に抽象化したいのですが、コードのいくつかのコードスニペットを持っていますか?
getattr(myUser.profile, 'get_setting_c')
ところで、eval
を使用すると、Is using eval in Python a bad practice?を参照して、Pythonで悪い習慣と考えられています。
なぜ
if eval('myUser.profile.get_setting_c') == True:
または
def fun(setting):
return eval('myUser.profile.%s' % setting)
if fun('get_setting_c') == True:
?
「attr = getattr(myUser.profile、 'get_setting_c'); attr == Trueの場合: – diofeher