Is it possible (and wise) to extend the None-type ?

Stef Mientki stef.mientki at gmail.com
Wed Nov 26 16:26:58 EST 2008


<snip>
> Alternative (if you *really* want to save the explicit test) is to
> attach the behaviour modification to the *relevant* class:
>
> class NonEvent(Event):
>    def do_nothing(self):
>       pass
>    skip = jump = hop = waltz = saunter = do_nothing
>    def __len__(self):
>       return 0
> NON_EVENT = NonEvent()
> del NonEvent
>
> # later:
>
> def amethod(self, event=NON_EVENT):
>    if event: # still works thanks to __len__ above
>       event.skip()
>    # now can avoid test, if desired
>    event.skip()
>
>   
thanks guys, the Null, Dummy, Skipper, Nonevent class works great
> HTH ... BTW, ever heard of PEP 8?
>   
I guess Python is missing some kind of CSS ;-)

cheers,
Stef



More information about the Python-list mailing list