[Python-Dev] PEP 461 - Adding % and {} formatting to bytes (original) (raw)
Ethan Furman ethan at stoneleaf.us
Wed Jan 15 22:32:01 CET 2014
- Previous message: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes
- Next message: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 01/15/2014 06:45 AM, Brett Cannon wrote: The PEP currently says::
format ------ The format mini language will be used as-is, with the behaviors as listed for %-interpolation. That's too vague; % interpolation does not support other format operators in the same way as str.format() does. % interpolation has specific code to support %d, etc. But str.format() gets supported for {:d} not from special code but because e.g. float.format('d') works. So you can't say "bytes.format() supports {:d} just like %d works with string interpolation" since the mechanisms are fundamentally different.
A question for anyone that has extensive experience in both %-formatting and .format-formatting: Would it be possible, at least for int and float, to take whatever is in the specifier and convert to %? Example:
"Weight: {wgt:-07f}".format(wgt=137.23)
would take the "-07f" and basically do a "%-07f" % 137.23 to get the ASCII to use?
--
Ethan
- Previous message: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes
- Next message: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]