简体   繁体   English

tweepy“未定义变量”错误

[英]tweepy “undefined variable” errors

I am new to both python and Aptana. 我是python和Aptana的新手。

I am trying to use the tweepy package in python. 我正在尝试在python中使用tweepy包。 I have the following code (from python's site ): 我有以下代码(来自python的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". 我收到“导入时未定义的变量: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. 我在Google上搜索, 发现了如何解决未定义的变量错误,但这似乎是一轮hack。 In sum, that link says to add "get_user" to globals in the preferences. 总之,该链接表示要在首选项中将“ get_user”添加到全局变量。

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. 作为Python和Aptana的新手,我只是想检查一下这是否是解决它的最佳方法。 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. 当我将“ tweepy.api.get_user”更改为“ tweepy.api.public_timeline”时,我遇到相同的错误,因此必须手动将“ public_timeline”添加到全局变量中。您必须手动配置每个变量。

thanks! 谢谢!

If you would like to not be warned about this you may exclude the warning: 如果您不想被警告,可以排除以下警告:

goto Window -> Preferences -> PyDev -> Editor -> Code Analysis 转到窗口->首选项-> PyDev->编辑器->代码分析

Click on the Undefined tab and add get_user to the textbox. 单击“未定义”选项卡,然后将get_user添加到文本框中。 That will clear up your warning. 这将清除您的警告。

Andrew 安德鲁

I had a Problem similar to your case (also using PyDev with Aptana). 我遇到了与您的情况类似的问题(也将PyDev与Aptana一起使用)。

I upgraded Aptana and PyDev with the following instructions: 我按照以下说明升级了Aptana和PyDev:

Update PyDev on Aptana 在Aptana上更新PyDev

after the upgrade PyDev worked just fine for me :) 升级之后,PyDev对我来说很好:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM