Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
django python eval_Python_Django - Fatal编程技术网

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