[Python-Dev] transitioning from % to {} formatting (original) (raw)
Eric Smith eric at trueblade.com
Wed Oct 7 20:21:01 CEST 2009
- Previous message: [Python-Dev] transitioning from % to {} formatting
- Next message: [Python-Dev] transitioning from % to {} formatting
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Antoine Pitrou wrote:
Vinay Sajip <vinaysajip yahoo.co.uk> writes:
"%0#8x" % 0x1234 '0x001234' "{0:0>#8x}".format(0x1234) '000x1234' Apart from the sheer unreadability of the {}-style format string, the result looks rather unexpected from a human being's point of view. (in those situations, I would output the 0x manually anyway, such as: "0x%06x" % 0x1234 '0x001234' "0x{:06x}".format(0x1234) '0x001234' )
"#" formatting was added to int.format in order to support this case:
format(10, '#6x') ' 0xa'
Without '#', there's no way to specify a field width but still have the '0x' up against the digits (at least not without generating an intermediate result and figuring out the width manually).
The fact that it works in combination with '0' or '>' (not sure which one makes it unreadable to you) wasn't really the point of the feature.
Eric.
- Previous message: [Python-Dev] transitioning from % to {} formatting
- Next message: [Python-Dev] transitioning from % to {} formatting
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]