http://docs.python.org/dev/library/ipaddress.html#module-ipa...
Am I the only one worries that Python is slowly turning into Java?
Instead of simple text/string for everything, now Class for everything, with nauty weird ill-defined Exceptions.
Am I the only one worries that Python is slowly turning into Java?
Instead of simple text/string for everything, now Class for everything, with nauty weird ill-defined Exceptions.
The example your are pointing out is for the module ipaddress which is for inspecting and manipulating ip addresses. It's not that Python now requires you to use ipaddress objects in place of strings for sockets.
In that case it's good to hear.
Hint: there’s more than /24 networks and IPv6 makes it even more complicated.
>>> str(ipaddress.ip_address('127.0.0.1'))
'127.0.0.1'
>>> str(ipaddress.ip_address('::1'))
'::1'
>>> str(ipaddress.ip_network('192.168.42.0/24'))
'192.168.42.0/24'
But you can do stuff like: >>> ipaddress.ip_address('192.168.42.23') in ipaddress.ip_network('192.168.42.0/24')
True
>>> ipaddress.ip_address('192.168.41.23') in ipaddress.ip_network('192.168.42.0/24')
False
or for addr in ipaddress.ip_network('192.168.42.0/24'):
print(adds)
Etc. I strongly suggest to have a look at http://docs.python.org/dev/howto/ipaddress.html#ipaddress-ho... to have an overview over it’s functionality – unfortunately the API docs aren’t done yet, but will be for 3.3 final.edit fixed code markup