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 [23]: a Out[23]: IPv4Address('1.2.3.4') In [24]: x = bin(int(a))[2:] In [25]: full_x = '0b' + ('0' * (32-len(x)) + x) In [26]: full_x Out[26]: '0b00000001000000100000001100000100' 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. eric On Mon, Feb 12, 2018 at 7:39 AM Christian Heimes <rep...@bugs.python.org> wrote: > > 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> > <https://bugs.python.org/issue32820> > _______________________________________ > ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32820> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com