[Python-Dev] sys.implementation

Steven D'Aprano steve at pearwood.info
Sat May 12 20:07:25 CEST 2012


Tres Seaver wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On 05/12/2012 08:04 AM, Nick Coghlan wrote:
>> On Sat, May 12, 2012 at 12:40 PM, Eric Snow
>> <ericsnowcurrently at gmail.com> wrote:
>>> If anyone has strong feelings for item-access over
>>> attribute-access, please elaborate.  I'm just not seeing it as that
>>> important and would rather finish up the PEP as simply as possible.
>> I object to adding a new type to the stdlib just for this PEP. Since 
>> iterating over the keys is significantly more useful than iterating 
>> over the values, that suggests a dictionary as the most appropriate 
>> type.
> 
> Why would anyone want to iterate over either of them?

1) I don't know what keys exist, so I use introspection on sys.implementation 
by iterating over the keys and/or values. E.g. dir(sys.implementation), or 
list(sys.implementation.keys()).

2) I know what keys exist, but I want to pretty-print the list of key/value 
pairs without having to explicitly write them out by hand:

print("spam", sys.implementation.spam)
print("ham", sys.implementation.ham)
print("cheese", sys.implementation.cheese)
# and so on...




-- 
Steven


More information about the Python-Dev mailing list