[Python-Dev] Py2.6 ideas (original) (raw)
"Martin v. Löwis" martin at v.loewis.de
Fri Feb 16 23:12:32 CET 2007
- Previous message: [Python-Dev] Py2.6 ideas
- Next message: [Python-Dev] Py2.6 ideas
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Raymond Hettinger schrieb:
d, g, v, t, r = model(somecontract)
I find that line quite unreadable, and find it likely that I would not be able to remember the standard order of the fields. You almost "had me" with the two fields example, but this makes me think "-1" again.
Is it really that you need all these values in the following computation? For stat, this was never the case: you would only need some field normaly (especially when the more esoteric, platform-dependent fields got added).
If you absolutely want tuple unpacking on a record-like object, I'd suggest to support explicit tuple conversion, like
d, g, v, t, r = model(somecontract).to_tuple()
Or, if you absolutely cannot stand the explicit tuple creation, add
def getitem(self, index): return getattr(self, self.slots[index]) # or is it self.[self.slots[index]] :-?
No need to inherit from tuple for that.
Of course, that specific example was solved long ago. We did not however expose a general purpose mechanism applicable where similar issues arise for other tuples.
As you've explained now, your use case is not similar. For os.stat, it's a means of transition and backwards compatibility. For your code, it seems you want it a permanent feature in your code.
Regards, Martin
- Previous message: [Python-Dev] Py2.6 ideas
- Next message: [Python-Dev] Py2.6 ideas
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]