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 <[email protected]> 
Sent: 28 April 2020 10:05
To: [email protected]
Subject: [Python-ideas] Re: Adding a "once" function to functools

On Tue, Apr 28, 2020 at 10:19:49AM +0200, Antoine Pitrou <[email protected]> 
wrote:
> On Tue, 28 Apr 2020 11:04:15 +1000
> Steven D'Aprano <[email protected]> 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/            [email protected]
           Programmers don't die, they just GOSUB without RETURN.
_______________________________________________
Python-ideas mailing list -- [email protected] To unsubscribe send an 
email to [email protected] 
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/H35YNUJTP23BPXE2SLH7JXVFBJ6CWDAJ/
Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/FKOL6OVGEGFKK76RDMKGZK32JNIBS6DG/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to