I am wondering how hard it would be to let some generators be resettable? I mean if you have a generator with initial conditions that change as it progresses, could it cache away those initial conditions and upon some signal, simply reset them? Objects of many kinds can be set up with say a reinit() method.
I am not saying Python needs such a language change for generators as in many programs you could just recreate a new instance of a generator. But there may be places where by the time the generator is used, the original is not known. Or, there are places where you want to lengthen something to match another by repeatedly copying the same sequence as many times as needed. If a generator finishes, you want it to restart with the same sequence until you stop asking. This is just a thought, not a request for such a feature. -----Original Message----- From: Python-list <python-list-bounces+avigross=verizon....@python.org> On Behalf Of ast Sent: Saturday, January 23, 2021 2:54 AM To: python-list@python.org Subject: Re: list() strange behaviour Le 20/12/2020 à 21:00, danilob a écrit : > > > b = ((x[0] for x in a)) > There is a useless pair of parenthesis b = (x[0] for x in a) b is a GENERATOR expression first list(b) calls next method on b repetedly until b is empty. So it provides the "content" of b second list(b) provides nothing since b is empty (there is no reset on generators) -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list