Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
tweepyを使用して最新のユーザーステータスを取得しようとしています
私のコードは
api = tweepy.API(auth) for status in tweepy.Cursor(api.user_timeline).items(): lastid = status.id laststatus = api.get_status(lastid).text break
できます。しかし、私はループを使用する必要があります。より良い方法はありますか?
.items()イテレータを返すので、呼び出すだけnext()で最初のアイテムを取得できます。
.items()
next()
status = next(tweepy.Cursor(api.user_timeline).items())
アイテムがまったくない場合、これにより例外が発生する可能性があります。これを防ぐためにStopIteration、デフォルトを追加できます。next()
StopIteration
status = next(tweepy.Cursor(api.user_timeline).items(), None)