名称错误:名称'process_or_store'未定义,Python。

3
我尝试运行这段代码,但出现了以下错误信息:

NameError: name 'process_or_store' is not defined

我已经尝试了所有相关的解决方案,但都没有起作用。请问该如何消除这个错误信息?
import tweepy
import json
import nltk

from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener



consumer_key = 'key'
consumer_secret = 'secret'
access_token = '-token'
access_secret = 'secret'

auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)

api = tweepy.API(auth)

for status in tweepy.Cursor(api.home_timeline).items(10):
    # Process a single status
     process_or_store(status.json)

2
你在哪里定义process_or_store方法? - R Nar
那么我该如何解决呢? - Afnan Humdan
你怎么定义它?你觉得 process_or_store 会从哪里来呢? - jonrsharpe
5
这段代码最初来自于 http://marcobonzanini.com/2015/03/02/mining-twitter-data-with-python-part-1/comment-page-1/#comment-258 的副本。 - enderland
3个回答

2
正如R Nar所提到的,process_or_store方法尚未定义。您可以在此处阅读有关如何执行此操作的更多信息。

正如作者所解释的那样

process_or_store()函数是您自定义实现的占位符。


1
我想这就是你要找的 -
    def process_or_store(tweet):
        print(json.dumps(tweet))

在使用这段代码之前,请不要忘记导入simplejson作为json。而且这是你提到的网站上可用的。


1

只需使用以下代码:

print(json.dumps(friend._json))

替换原有代码中的

process_or_store(friend._json)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接