[Python-Dev] Py2.6 ideas
"Martin v. Löwis"
martin at v.loewis.de
Fri Feb 16 23:12:32 CET 2007
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
More information about the Python-Dev
mailing list