On Nov 12, 7:21 am, rusi <[email protected]> wrote:
> On Nov 12, 12:09 pm, rusi <[email protected]> wrote:> This is a classic
> problem -- structure clash of parallel loops
>
> <rest snipped>
>
> Sorry wrong solution :D
>
> The fidgetiness is entirely due to python not allowing C-style loops
> like these:
>
> >> while ((c=getchar()!= EOF) { ... }
> [...]
There are actually three fidgety things going on:
1. The API is 1-based instead of 0-based.
2. You don't know the number of pages in advance.
3. You want to process tweets, not pages of tweets.
Here's yet another take on the problem:
# wrap fidgety 1-based api
def search(i):
return api.GetSearch("foo", i+1)
paged_tweets = (search(i) for i in count())
# handle sentinel
paged_tweets = iter(paged_tweets.next, [])
# flatten pages
tweets = chain.from_iterable(paged_tweets)
for tweet in tweets:
process(tweet)
--
http://mail.python.org/mailman/listinfo/python-list