Evil hack of the day

Evan Simpson evan at tokenexchange.com
Thu May 27 20:37:45 EDT 1999


Nifty!  The more I see "default abuse", the more I can't help but think that
it should be elevated to a feature.  After all, the only thing that really
makes this "abuse", is the fact that the "statics" masquerade as function
parameters.  How about legitimizing them by allowing a section after normal
parameters (after a ';'?) which lets us write:

telly = ("on", "off", "covered with penguin guts")
penguin = ("alive", "sleeping", "blown to bits")
from string import join

def tellystatus(i=0, s="The telly is %s" ; telly, penguin, strjoin = join):
    return strjoin([s % telly[i], "The penguin is", penguin[i]])

>>> tellystatus()
'The telly is on The penguin is alive'
>>> tellystatus(1)
'The telly is off The penguin is sleeping'
>>> tellystatus(2, "The TV is %s")
'The TV is covered with penguin guts The penguin is blown to bits'
>>> tellystatus(0, "The fridge is %s", ('closed', 'open', 'fragged'))
Traceback (innermost last):
  File "<stdin>", line 1, in ?
TypeError: too many arguments; expected 2, got 3
>>> tellystatus(penguin=None):
Traceback (innermost last):
  File "<stdin>", line 1, in ?
TypeError: unexpected keyword argument: penguin

Neel Krishnaswami wrote in message <7ihvh9$1bm$1 at brick.cswv.com>...
[don't touch it... it's evil! snipped]






More information about the Python-list mailing list