This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients Arfrever, Christian H, barry, belopolsky, eric.smith, gotgenes, gregory.p.smith, ncoghlan, vstinner
Date 2017-05-02.02:10:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1493691058.82.0.329524453522.issue22385@psf.upfronthosting.co.za>
In-reply-to
Content
Minimalist proposal:

    def hex(self, *, bytes_per_group=None, delimiter=" "):
        """B.hex() -> string of hex digits
        B.hex(bytes_per_group=N) -> hex digits in groups separated by *delimeter*
    
        Create a string of hexadecimal numbers from a bytes object::

        >>> b'\xb9\x01\xef'.hex()
        'b901ef'
        >>> b'\xb9\x01\xef'.hex(bytes_per_group=1)
        'b9 01 ef'
        """

Alternatively, the grouping could be by digit rather than by byte:

    def hex(self, *, group_digits=None, delimiter=" "):
        """B.hex() -> string of hex digits
        B.hex(group_digits=N) -> hex digits in groups separated by *delimeter*
    
        Create a string of hexadecimal numbers from a bytes object::

        >>> b'\xb9\x01\xef'.hex()
        'b901ef'
        >>> b'\xb9\x01\xef'.hex(group_digits=2)
        'b9 01 ef'
        """

One potential advantage of the `group_digits` approach is that it could be fairly readily adapted to the hex/oct/bin builtins (although if we did that, it would make the lack of a "dec" builtin for decimal formatting a bit weird)
History
Date User Action Args
2017-05-02 02:10:59ncoghlansetrecipients: + ncoghlan, barry, gregory.p.smith, belopolsky, vstinner, eric.smith, gotgenes, Arfrever, Christian H
2017-05-02 02:10:58ncoghlansetmessageid: <1493691058.82.0.329524453522.issue22385@psf.upfronthosting.co.za>
2017-05-02 02:10:58ncoghlanlinkissue22385 messages
2017-05-02 02:10:58ncoghlancreate