[OT] New to Python: Features
Richard Blackwood
richardblackwood at cloudthunder.com
Thu Oct 7 10:53:46 EDT 2004
Oh no, I thought I wrote that accident. I don't like any brackets or
else. I like to write: foo x, y or foo: x,y
I prefer the latter actually.
>hmmm, closest I can come is...:
>
>class MakeEugeniHappy(object):
> def __init__(self, f):
> self.f = f
> def __getitem__(self, args):
> if isinstance(args, tuple): return self.f(*args)
> else: return self.f(args)
>
>@ MakeEugeniHappy
>def f(x): return x*3+1
>
>Now, 'print f[23]' emits 70. No way to call functions without
>arguments, and a bit of a mess to call one with an argument that's a
>tuple (I decided f[1,2,3] had better map to the original f(1,2,3) -- so
>to call the original f((1,2,3)) you need f[(1,2,3),] ...!-). One way
>around the "call without arguments" would be to check if
>isinstance(args, slice) and specialcase slices with None for all
>attributes, so f[:] would call the original f().
>
>
Are you saying that if I have only one argument then I may drop the
parenthesis? Naw, your not saying that.
More information about the Python-list
mailing list