[Python-ideas] PEP 4XX: Adding sys.implementation
Steven D'Aprano
steve at pearwood.info
Wed May 2 03:09:17 CEST 2012
Eric Snow wrote:
> On Mon, Apr 30, 2012 at 3:04 PM, Barry Warsaw <barry at python.org> wrote:
>> On Apr 27, 2012, at 12:36 AM, Eric Snow wrote:
>>> ``sys.implementation`` is a dictionary, as opposed to any form of "named"
>>> tuple (a la ``sys.version_info``). This is partly because it doesn't
>>> have meaning as a sequence, and partly because it's a potentially more
>>> variable data structure.
>> I agree that sequence semantics are meaningless here. Presumably, a
>> dictionary is proposed because this
>>
>> cache_tag = sys.implementation.get('cache_tag')
>>
>> is nicer than
>>
>> cache_tag = getattr(sys.implementation, 'cache_tag', None)
>
> That's a good point. Also, a dict better reflects a collection of
> variables that a dotted-access object, which to me implies the
> potential for methods as well.
Dicts have methods, and support iteration.
A dict suggests to me that an arbitrary number of items could be included,
rather than suggesting a record-like structure with an fixed number of items.
(Even if that number varies from release to release.)
On the other hand, a dict supports iteration, and len, so even if you don't
know how many fields there are, you can always find them by iterating over the
record.
Syntax-wise, dotted name access seems right to me for this, similar to
sys.float_info. If you know a field exists, sys.implementation.field is much
nicer than sys.implementation['field'].
I hate to admit it, but I'm starting to think that the right solution here is
something like a dict with dotted name access.
http://code.activestate.com/recipes/473786
http://code.activestate.com/recipes/576586
sort of thing.
--
Steven
More information about the Python-ideas
mailing list