
On 2 May 2017 at 03:34, Ethan Furman <ethan@stoneleaf.us> wrote:
On 05/01/2017 07:04 AM, Juancarlo AƱez wrote:
On Mon, May 1, 2017 at 9:38 AM, Nick Coghlan wrote:
just support two keyword arguments to hex(): "delimiter" (as you suggest) and "chunk_size" (defaulting to 1, so you get per-byte chunking by default)
I'd expect "chunk_size" to mean the number of hex digits (not bytes) per chunk.
I was also surprised by that. Also, should Python be used on a machine with, say, 24-bit words then a chunk size of three makes more sense that one of 1.5. ;)
I came up with a possible alternative scheme on the issue tracker: 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' """ Advantages of this approach: - grouping by digits generalises more obviously to other bases (e.g. if similar arguments were ever added to the hex/oct/bin builtins) - by using "group_digits=None" to indicate "no grouping", the default delimiter can be a space rather than the empty string Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia