简体   繁体   中英

Iterating over dict and values don't always print

I'm having a really strange issue here that I can't figure out. The first time the following code executes, it works as you would expect, cities and countries are printed correctly. Every time after that, nothing is printed.

for tweet in tweets:
    city = tweet['city']
    country = tweet['country']
    print("{}, {}".format(city, country))

If I just print the entire dict, I can see that city and country ARE in there and they have values. I do have some worker threads in the background that update the city and country, but I can't figure out why that would affect it, if it is.

The problem, for anyone that happens to have a similar issue, was that in my __next__ function in my Tweet class I wasn't resetting the iterator. So after iterating over the object once, the position was at the end of the list and was never being put back at the beginning.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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