[Python-Dev] PEP 426 comment: field order
Barry Warsaw
barry at python.org
Fri Oct 19 16:20:25 CEST 2012
On Oct 18, 2012, at 09:23 PM, Daniel Holth wrote:
>The email module provides an ordered multidict interface to the data.
>The first tag wins (if you improperly define Name: twice for example),
>but the order of everything is preserved. We just don't need it,
>except that it might be surprising to see your classifiers randomly
>re-ordered.
Just to be clear, the email package preserves both the order and presence of
headers. So if you do add Name: twice, both will be retained. Plenty of
email headers (e.g. Received) can appear multiple times.
The getitem API will indeed return just the first entry, but there is an
alternative API that you can use to get all of them, in order. Deletions and
re-insertions obviously change the order (the insertion is always an append),
although there is a .replace_header() method for preserving existing order
(kind of - only for the first instance of a header).
Cheers,
-Barry
More information about the Python-Dev
mailing list