tweepy “undefined variable” errors

微笑、不失礼 提交于 2019-12-08 10:25:15

问题


I am new to both python and Aptana.

I am trying to use the tweepy package in python. I have the following code (from python's site):

import tweepy

user = tweepy.api.get_user('twitter') # "undefined variable" error occurs on this line
print user.screen_name
print user.followers_count
for friend in user.friends():
    print friend.screen_name

I get an "Undefined variable from import: get_user". The code actually runs fine with no errors and produces the expected results. I googled and found how to resolve the undefined variable error, but it seems like a hack-a-round. In sum, that link says to add "get_user" to globals in the preferences.

Being new to both Python and Aptana, I just wanted to check to see if that is the best way to resolve it....it just seems like a hack. When I change "tweepy.api.get_user" to "tweepy.api.public_timeline" I get the same error and thus will have to manually add "public_timeline" to the globals....It doesn't seem like the correct way when you have to manually configure each variable.

thanks!


回答1:


If you would like to not be warned about this you may exclude the warning:

goto Window -> Preferences -> PyDev -> Editor -> Code Analysis

Click on the Undefined tab and add get_user to the textbox. That will clear up your warning.

Andrew




回答2:


I had a Problem similar to your case (also using PyDev with Aptana).

I upgraded Aptana and PyDev with the following instructions:

Update PyDev on Aptana

after the upgrade PyDev worked just fine for me :)



来源:https://stackoverflow.com/questions/11907478/tweepy-undefined-variable-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!