[issue22385] Allow 'x' and 'X' to accept bytes-like objects in string formatting

Eric V. Smith report at bugs.python.org
Thu Sep 11 09:34:35 CEST 2014


Eric V. Smith added the comment:

I'm not particularly wild about the .precision syntax either, but I think the feature is generally useful.

Adding bytes.__format__ is exactly what "special output for bytes" _is_, as far as format() is concerned.

Another option would be to invent a new format specification for bytes. There's no reason it needs to follow the same syntax as for str, int, etc., except for ease of remembering the syntax, and some code reuse.

For example, although it's insane, you could do:

format(b'abcdwxyz', 'use_spaces,grouping=4,add_prefix')
  -> '0x61626364 0x7778797a'

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22385>
_______________________________________


More information about the Python-bugs-list mailing list