R. David Murray <[email protected]> added the comment:
These are actually reasonable requests, and in fact have been brought up before
and implemented:
>>> x =
>>> urlparse('http://me:[email protected]:800/foo;key1=value1?key2=value2#key3=value3#key4=value4')
>>> x
ParseResult(scheme='http', netloc='me:[email protected]:800', path='/foo',
params='key1=value1', query='key2=value2', fragment='key3=value3#key4=value4')
>>> x.hostname
'example.com'
>>> x.port
800
>>> x.username
'me'
>>> x.password
'mypass'
>>> x._asdict()
OrderedDict([('scheme', 'http'), ('netloc', 'me:[email protected]:800'),
('path', '/foo'), ('params', 'key1=value1'), ('query', 'key2=value2'),
('fragment', 'key3=value3#key4=value4')])
Now, what this doesn't get you is the "extra" fields that are not part of the
base tuple. The base tuple has the members it does for backward compatibility.
So, the thing to discuss on python-ideas would be an API for namedtuple that
gets you the extra fields.
None versus the empty string is not something that can happen, for backward
compatibility reasons, even if there was agreement that it was better.
I'm not entirely sure why dict(x) is not supported (but I suspect it is because
x is "a tuple", again for backward compatibility reasons), so you might search
the archives to find out why for sure, if you are curious.
----------
nosy: +r.david.murray
resolution: -> out of date
stage: -> resolved
status: open -> closed
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue33480>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com