[Tutor] how to temporarily disable a function

Christopher King g.nius.ck at gmail.com
Thu Jul 28 19:02:12 CEST 2011


On Thu, Jul 28, 2011 at 5:08 AM, Peter Otten <__peter__ at web.de> wrote:

> Pete O'Connell wrote:
>
> > Hi I was wondering if there is a way to disable a function.
>
>
You could use this decorator:
class Disabler(object):
    def __init__(self, old_function):
        self.__old = old_function
        self.enabled=True
    def __call__(self, *arg, **kwd):
        if enabled: return self.__old(*arg, **kwd)
    def enable(self): self.enabled = True
    def disable(self): self.enabled=False


> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110728/01b4e86e/attachment.html>


More information about the Tutor mailing list