django python eval
我想将一些代码片段抽象为一个函数,该函数只有一个需要动态的小更改django python eval,python,django,Python,Django,我想将一些代码片段抽象为一个函数,该函数只有一个需要动态的小更改 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\u setting\u c') 顺便说一句,在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\u setting\u c')
顺便说一句,在python中使用eval
被认为是不好的做法,请参见。这就是您想要的吗
getattr(myUser.profile,'get\u setting\u c')
顺便说一句,在python中使用eval
被认为是不好的做法,请参见。为什么不
if eval('myUser.profile.get_setting_c') == True:
或
为什么不呢
if eval('myUser.profile.get_setting_c') == True:
或
?仅需完成:分配给一个变量,如“attr=getattr(myUser.profile,'get_setting_c');如果attr==True:“仅需完成:分配给一个变量,如“attr=getattr(myUser.profile,'get_setting_c');如果attr==True:“Becasue func('get_setting_c或True')给出TrueBecasue func('get_setting_c或True')给出True