Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.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
Python dict调用函数作为值_Python_Json_Function_Loops - Fatal编程技术网

Python dict调用函数作为值

Python dict调用函数作为值,python,json,function,loops,Python,Json,Function,Loops,我正在使用返回的json在python中创建dict 我希望其中一个值是shortuuid,因此我将一个函数作为值。 我希望调用该函数,并用该函数返回的值替换该值 这是正确的吗 tvMSG = {'fromEMAIL': uEmail, 'toCHANNELID': channelID, 'timeSENT': uTime} for msgkey, subdict, instakey in (('profilePIC', 'user', 'profile

我正在使用返回的json在python中创建dict

我希望其中一个值是shortuuid,因此我将一个函数作为值。 我希望调用该函数,并用该函数返回的值替换该值

这是正确的吗

        tvMSG = {'fromEMAIL': uEmail, 'toCHANNELID': channelID, 'timeSENT': uTime}
             for msgkey, subdict, instakey in (('profilePIC', 'user', 'profile_picture'),
                         ('userNAME', 'user', 'username'),
                         ('msgBODY', 'caption', 'text'),
                         ('mainCONTENT','images', 'standard_resolution',)
                         ('tvshowID', shortuuid.uuid())):



   this is the key/value in question:
            ('tvshowID', shortuuid.uuid())):
这是我得到的错误:

        TypeError: 'tuple' object is not callable

如果没有,我该怎么做?

谢谢@ThierryJ的提示

  tvMSG = {'fromEMAIL': uEmail, 'toCHANNELID': channelID, 'timeSENT': uTime, 'tvshowID: shortuuid.uuid()}
         for msgkey, subdict, instakey in (('profilePIC', 'user', 'profile_picture'),
                     ('userNAME', 'user', 'username'),
                     ('msgBODY', 'caption', 'text'),
                     ('mainCONTENT','images', 'standard_resolution')):
不需要进行任何迭代。
我只是将该调用从循环中取出并放入循环上方的变量中。

谢谢@ThierryJ的提示

  tvMSG = {'fromEMAIL': uEmail, 'toCHANNELID': channelID, 'timeSENT': uTime, 'tvshowID: shortuuid.uuid()}
         for msgkey, subdict, instakey in (('profilePIC', 'user', 'profile_picture'),
                     ('userNAME', 'user', 'username'),
                     ('msgBODY', 'caption', 'text'),
                     ('mainCONTENT','images', 'standard_resolution')):
不需要进行任何迭代。
我只是将该调用从循环中取出,并将其放入循环上方的变量中。

错误源于缺少逗号。该行:

('mainCONTENT','images', 'standard_resolution',)
实际上应该是:

('mainCONTENT','images', 'standard_resolution'),

这就是为什么您得到错误“tuple”对象不可调用的原因,您调用的是
(“any”,“tuple”)(“arguments”)
,错误来自缺少逗号。该行:

('mainCONTENT','images', 'standard_resolution',)
实际上应该是:

('mainCONTENT','images', 'standard_resolution'),

这就是为什么您得到了错误
“tuple”对象不可调用的原因
,您调用了
('any','tuple')('arguments')

它不能正常工作吗?不,我得到了这个错误。。。。TypeError:“tuple”对象不可调用这是正确的方法。但是,您正在遍历一个3元组的列表,而最后一个仅为2元组。它是否按原样工作?不,我得到了这个错误。。。。TypeError:“tuple”对象不可调用这是正确的方法。但是,您正在遍历一个3元组的列表,而最后一个仅为2元组!修复了2个问题…错误和str8使代码超出了预期!修复了2个问题…错误并将代码输出