summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Doc/library/ipaddr.rst10
1 files changed, 10 insertions, 0 deletions
diff --git a/Doc/library/ipaddr.rst b/Doc/library/ipaddr.rst
index 1178204d26..6a10895ea4 100644
--- a/Doc/library/ipaddr.rst
+++ b/Doc/library/ipaddr.rst
@@ -199,6 +199,16 @@ both IPv4 and IPv6.
1 if self.version > other.version
eg: IPv6('::1/128') > IPv4('255.255.255.0/24')
+ .. note::
+
+ To sort networks with :func:`sorted`, :func:`min`, :func:`max` and
+ other tools with a *key* argument, use the :func:`operator.attrgetter`
+ function to extract the relevant fields::
+
+ >>> from operator import attrgetter
+ >>> s = [IPv6('::1/128'), IPv4('255.255.255.0/24')]
+ >>> sorted(s, key=attrgetter('version', 'network', 'netmask'))
+ [IPv4('255.255.255.0/24'), IPv6('::1/128')]
.. method:: subnet(prefixlen_diff=1)