Eric Osborne <e...@notcom.com> added the comment:
It is often useful to have non-decimal representations of IP addresses.
Hex shows up a lot in sniffer traces, which is why I wanted to provide
__index__, but that's not going to happen. I use binary a lot when
teaching subnet masking and address summarization - if you line up bit
patterns it's much easier to show how things lay out. It's easy enough to
use bin(int(addr)) but that doesn't zero-pad the string it returns. I find
myself doing something like
In : a
In : x = bin(int(a))[2:]
In : full_x = '0b' + ('0' * (32-len(x)) + x)
In : full_x
Although, as Eric Smith has pointed out, there's a one liner way to do
this. But if an IP address can represent itself as an integer (IMO the
least useful form) it should have at least a binary representation, and
lack of a seperate __bin__ means this is as close as I could get.
On Mon, Feb 12, 2018 at 7:39 AM Christian Heimes <rep...@bugs.python.org>
> Christian Heimes <li...@cheimes.de> added the comment:
> I agree with Serhiy and Eric. It's a needless complication of the module.
> What's the actual use case of printing a human readable bit representation
> of an IP address?
> nosy: +christian.heimes
> Python tracker <rep...@bugs.python.org>
Python tracker <rep...@bugs.python.org>
Python-bugs-list mailing list