无法从我的函数返回字典

2024-07-05 14:56:07 发布

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

我得到一个无效的语法错误

 SyntaxError: invalid syntax
 root@collabnet:/home/projects/twitterBot# python twitterBot2.py
 File "twitterBot2.py", line 58
 return screenNames

从该函数返回字典时:

^{pr2}$

我是这样运行函数的:

 toPrint = {}#Testing Only
 print "users following", userid 
 toPrint = getUserName(followingids)#Testing Only

我尝试过注释并只打印screenNames,但是我仍然得到相同的错误,除了print语句。我很确定我的退货是正确的谢谢你的外观。在


Tags: 函数pyonlyhomeroottestingprintsyntax
1条回答
网友
1楼 · 发布于 2024-07-05 14:56:07

您忘记了前一行的右括号:

screenNames.append(zip(toGet, toAppend)
#                 ^   ^               ^^?
#                 |   \   closed  -/|
#                 \  - not closed  -/

这里还有另一个问题,因为screenNames是一个dict对象,不是一个列表,并且没有.append()方法。如果要用键值对更新字典,请改用update()

^{pr2}$

相关问题 更多 >