[issue20860] ipaddress network subnets() method should return object with __getitem__

2014-03-06 Thread Warren Turkal
New submission from Warren Turkal: It would be very useful to be able to not only iterate through subnets, but also index a subnet. For example, I would really like to be able to do the following: import ipaddress as ipa net = ipa.ip_network('10.0.0.0/8')

[issue20860] ipaddress network subnets() method should return object with __getitem__

2014-03-06 Thread R. David Murray
R. David Murray added the comment: I think you are looking for list(net.subnets(prefixlen_diff=2))[2]. This is the standard Python way of going from an iterator to an indexable collection. -- nosy: +r.david.murray resolution: - rejected stage: - committed/rejected status: open -

[issue20860] ipaddress network subnets() method should return object with __getitem__

2014-03-06 Thread Warren Turkal
Warren Turkal added the comment: Won't that instantiate an object for each item in the list though? For example: list(net.subnets(prefixlen_diff=16))[499] This take a long time. I was trying to think of a way to lazily instantiate. For example, I don't want to create 65536 network objects

[issue20860] ipaddress network subnets() method should return object with __getitem__

2014-03-06 Thread R. David Murray
R. David Murray added the comment: The interface you are suggesting isn't consistent with other stdlib APIs. Perhaps it would be better to discuss this concept on pyhon-ideas...additional methods for computing the number of subnets for a given prefix, and a different one for constructing one

[issue20860] ipaddress network subnets() method should return object with __getitem__

2014-03-06 Thread R. David Murray
R. David Murray added the comment: Or maybe a subnet_range method that returns a range-like object. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20860 ___

[issue20860] ipaddress network subnets() method should return object with __getitem__

2014-03-06 Thread STINNER Victor
STINNER Victor added the comment: It would be very useful to be able to not only iterate through subnets, but also index a subnet. For your information, the IPy module supports that: tuple(IPy.IP('192.168.1.128/31')) (IP('192.168.1.128'), IP('192.168.1.129')) IPy.IP('2000::/3')[2**120]

[issue20860] ipaddress network subnets() method should return object with __getitem__

2014-03-06 Thread STINNER Victor
STINNER Victor added the comment: I reopen the issue because the list option may create an huge list. Try the IPv6 2000::/3 network :-) -- nosy: +haypo resolution: rejected - status: closed - open ___ Python tracker rep...@bugs.python.org