Python dict call函数作为valu

2024-10-05 11:07:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用返回的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())):

这是我得到的错误:

^{pr2}$

如果没有,我该怎么做?在


Tags: 函数injsonuuiddictuserchannelidutime
2条回答

谢谢你的提示@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',)

实际上应该是:

^{pr2}$

这就是为什么你得到错误'tuple' object is not callable,你调用了('any','tuple')('arguments')。在

相关问题 更多 >

    热门问题