returning unordered keyword arguments from a function (WAS: Are multiple return values really harmful?)

Fernando Perez fperez528 at yahoo.com
Thu Nov 18 16:48:45 EST 2004


Steven Bethard wrote:

> Fernando Perez wrote:
>> Steven Bethard wrote:
> [snip]
>>>>>> r = object(year=2004, month=11, day=18)
>>>>>> r.day, r.month, r.year
>>>
>>>(18, 11, 2004)
>> 
>> 
>> Given that the necessary class is literally a 3-liner, I'm not sure a
>> language extension is truly needed:
>> 
>> In [1]: class bunch:
>>    ...:     def __init__(self,**kw):
>>    ...:         self.__dict__.update(kw)
>>    ...:
> 
> How do you think I generated the code above? ;)

:)

> On the other hand, I usually find that in the few places where I have
> used a record like this, I eventually replace the struct with a real
> class...

Yes, that's true.  IPython has this fairly fancy Struct module, which is
yet-another-shot at the same thing.  It started as the above 3-liner, and
ended up growing into a fairly complex class:

planck[IPython]> wc -l Struct.py
376 Struct.py

Not huge, but certainly more than 3 lines :)

I guess I was only arguing for the 3-line version being fairly trivial even to
rewrite on the fly as needed.  But if someone does add a fully functional
contribution of this kind, with enough bells and whistles to cover the more
advanced cases, I'd be +100 on that :)

Best,

f




More information about the Python-list mailing list