Questions
Within a generator function, how can I find out if it has yielded anything yet?
def my_generator(stuff):
# complex logic that interprets stuff and may or may not yield anything
# I only want to yield this if nothing has been yielded yet.
yield Nothing could be done with the input.
Answers
You d need to keep a flag yourself, or restructure the code at the top. If things are too complex, it sounds like your function might do too much.
Also, if that s your message, it sounds like you may want an exception instead.
Source
License : cc by-sa 3.0
http://stackoverflow.com/questions/11730833/python-2-7-has-anything-been-yielded
Related