How can I tell whether a generator was just-started?
This only works in Python 3.2+: >>> def gen(): yield 0; yield 1 … >>> a = gen() >>> import inspect >>> inspect.getgeneratorstate(a) ‘GEN_CREATED’ >>> next(a) 0 >>> inspect.getgeneratorstate(a) ‘GEN_SUSPENDED’ >>> next(a) 1 >>> inspect.getgeneratorstate(a) ‘GEN_SUSPENDED’ >>> next(a) Traceback (most recent call last): File “<stdin>”, line 1, in <module> StopIteration >>> inspect.getgeneratorstate(a) ‘GEN_CLOSED’ So, the … Read more