diff options
author | Raymond Hettinger <python@rcn.com> | 2009-05-14 15:31:02 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2009-05-14 15:31:02 (GMT) |
commit | 9aaef2da4d53341cec20d2b8d72814d3b1503b9e (patch) | |
tree | 96f3cabd5759a5545aad7e44dd99990d3ff03a12 /Doc | |
parent | da0dc2e468552560af6d8d8988e05c9b75a93b61 (diff) | |
download | cpython-9aaef2da4d53341cec20d2b8d72814d3b1503b9e.zip cpython-9aaef2da4d53341cec20d2b8d72814d3b1503b9e.tar.gz cpython-9aaef2da4d53341cec20d2b8d72814d3b1503b9e.tar.bz2 |
Suggest how to use compare_networks() with a modern Python.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/ipaddr.rst | 10 |
1 files changed, 10 insertions, 0 deletions
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) |