python-2.1 function attributes
Emile van Sebille
emile at fenx.com
Fri Jan 26 11:05:26 EST 2001
Let's see if I can pare down the interactive session
properly:
>>> 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):
--or--
d = {'a':44,'b':55,'c':66}
def test(...) having (**d):
which, to my eye, doesn't nearly get in the flow as mush
<oops ;-)>; allows either list or dictionary arguments;
doesn't require a specific named variable to be present at
that specific location (ala __attribute__); and allows other
functions to extend easily, as eg:
myfunc_attrs = {}
...
myfunc_attrs['unittest'] = """..."""
...
def myfunc(...) having (**myfunc_attrs):
See you,
--
Emile van Sebille
emile at fenx.com
-------------------
"Michael Hudson" <mwh21 at cam.ac.uk> wrote in message
news:m34rymxt4u.fsf at atrus.jesus.cam.ac.uk...
> "Emile van Sebille" <emile at fenx.com> writes:
>
> > I also like it without the dot, as it opens the door to
> > allowing *args and **kwargs style parameter passing
> > interpretation.
>
> What would that mean?
>
> def f(*a=1):
> print 1
>
> is a syntax error today...
>
> Cheers,
> M.
>
> --
> ROOSTA: Ever since you arrived on this planet last
night you've
> been going round telling people that you're
Zaphod
> Beeblebrox, but that they're not to tell anyone
else.
> -- The Hitch-Hikers Guide to the
Galaxy, Episode 7
More information about the Python-list
mailing list