tweepy “undefined variable” errors

2019-06-13 03:49发布

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!

2条回答
Emotional °昔
2楼-- · 2019-06-13 04:23

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 :)

查看更多
贼婆χ
3楼-- · 2019-06-13 04:29

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

查看更多
登录 后发表回答