Am I missing something here? ipaddress vs socket

Chris Angelico rosuav at gmail.com
Fri May 1 08:06:12 EDT 2015


On Fri, May 1, 2015 at 8:41 PM, Ronald van Zantvoort
<the.loeki at gmail.com> wrote:
> mystring is already an IP address, sorry for not mentioning that.
> The point is that ternary if; I've been scouring around the internet and there's a million different variations on the same idea.
> I'm completely flabberghasted it's not a simple property within the object though, e.g. ip.sock_family.
>
> Was this a deliberate decision by the Python devs or can I try an RFE for that?

You could ask. At very worst, you'll find someone explain to you why
it shouldn't be done. I suggest using the python-ideas mailing list;
people there are usually reasonably friendly, though occasionally you
find a caustic response to a dumb idea like "Python should use braces
for indentation" :)

>> But you may find it convenient to use a dedicated function for
>> establishing a connection, which could look up an AAAA or A record for
>> a name, then proceed through all addresses, attempting connections in
>> turn. I'm fairly sure one exists in Python, but I can't right now
>> remember the name.
>>
> Well you've already got socket.create_connection(), which (I think) does perform that lookup.

Yeah, I went looking for it and came across that, but wasn't sure if
that was it.

Now I look more closely (ie: look at the actual source code), I see
that it probably is the function I was thinking of. Might need a docs
patch to make it clear that this iterates over getaddrinfo() and
attempts them all in succession.

ChrisA



More information about the Python-list mailing list