Yield does not work, but return does
This question already has an answer here:
By putting a yield
statement in the join
method, you're making it a generator. Calling a generator method just creates a generator function; you need to iterate through it to get data. However, since execution inside a generator stops every time it hits a yield statement, you need to exhaust all of its contents if you want it to fully run.
This way your code runs all the way through:
join_gen = bot.join(channels)
for error_msg in join_gen:
print error_msg
Generators in the Python 2 docs
I'm not sure a generator is a good option for you here though. You might be better served returning response
right when you have the first error, or if you want to go through all the channels, append each error response to an error list and return that list when you're done.
上一篇: 对产量的基本理解
下一篇: 收益不起作用,但回报确实