[OT] New to Python: Features
richardblackwood at cloudthunder.com
Thu Oct 7 16:53:46 CEST 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...:
> def __init__(self, f):
> self.f = f
> def __getitem__(self, args):
> if isinstance(args, tuple): return self.f(*args)
> else: return self.f(args)
>def f(x): return x*3+1
>Now, 'print f' 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