Actually the draw examples made me think that possibly the @once, @run_once or whatever decorator should possibly add a reset method, as does the lru_cache cache_clear function. Taking the gunslinger draw example it would be: @once def draw(): """ Get your gun """ # Get your gun ... return gun def shoot(targets): for target in targets: gun_in_hand = draw() gun_in_hand.fire_at(target) This would speed up shooting nicely but you would have tied up a valuable resource but it would be really handy to have: def holster_gun(): """ Finished with gun for now """ draw.reset() One of the issues that newcomers to iterators suffer from is the fact that you need to delete and recreate them if you need to re-use them from the beginning however removing and redefining a function is much more complex. Steve Barnes -----Original Message----- From: Oleg Broytman <phd@phdru.name> Sent: 28 April 2020 10:05 To: python-ideas@python.org Subject: [Python-ideas] Re: Adding a "once" function to functools On Tue, Apr 28, 2020 at 10:19:49AM +0200, Antoine Pitrou <solipsis@pitrou.net> wrote:
On Tue, 28 Apr 2020 11:04:15 +1000 Steven D'Aprano <steve@pearwood.info> wrote:
Yes, it's annoying when English words can have two or more meanings. The first time I can across math.sin, I was very excited, until I realised it was just the trigonometric function :-(
This is the gunslinger.draw versus the artist.draw problem.
It should be solved by the random.draw solution (which calls one or the other, randomly ;-)).
But only once! :-D
Regards
Antoine.
Oleg. -- Oleg Broytman https://phdru.name/ phd@phdru.name Programmers don't die, they just GOSUB without RETURN. _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/H35YNU... Code of Conduct: http://python.org/psf/codeofconduct/