python-2.1 function attributes
Michael Hudson
mwh21 at cam.ac.uk
Fri Jan 26 11:29:50 EST 2001
"Emile van Sebille" <emile at fenx.com> writes:
> Let's see if I can pare down the interactive session
> properly:
Oh, I see what you mean.
> >>> def test(a=1,b=2,c=3):
> print 'test . a,b,c =', a,b,c
> >>> l = (4,5,6)
> >>> test(*l)
> test . a,b,c = 4 5 6
> >>> d = {'a':44,'b':55,'c':66}
> >>> test(**d)
> test . a,b,c = 44 55 66
>
> There, that looks OK. By adopting this in, eg:
>
> def test(...) having (a=1, b=2, c=3):
>
> you'd be able to write either:
>
> l = (4,5,6)
> def test(...) having (*l):
Uhh, how do you propose to refer to the elements of l? test.0?
> --or--
>
> d = {'a':44,'b':55,'c':66}
> def test(...) having (**d):
This would work, but I'm slightly agin it; if you're doing stuff
out-of-line *anyway*, you can do
d = {'a':44,'b':55,'c':66}
def test(...):
...
test.__dict__.update(d)
Hmm.
BTW, I've implemented my proposal at:
http://sourceforge.net/patch/?func=detailpatch&patch_id=103441&group_id=5470
You need a *really* recent Python (i.e. CVS from later than yesterday)
to get this to work (Jeremy checked in the code for PEP 227, static
nested scopes, which really beat up the compiler). But give it a
whirl!
Cheers,
M.
--
If you don't use emacs, you're a pathetic, mewling, masochistic
weakling and I can't be bothered to convert you. -- Ron Echeverri
More information about the Python-list
mailing list