mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Suggest how to use compare_networks() with a modern Python.
This commit is contained in:
parent
da0dc2e468
commit
9aaef2da4d
1 changed files with 10 additions and 0 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue