From 9aaef2da4d53341cec20d2b8d72814d3b1503b9e Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Thu, 14 May 2009 15:31:02 +0000 Subject: Suggest how to use compare_networks() with a modern Python. --- Doc/library/ipaddr.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Doc/library/ipaddr.rst b/Doc/library/ipaddr.rst index 1178204..6a10895 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) -- cgit v0.12