Replace weird error message?

Chris Angelico rosuav at gmail.com
Wed Mar 16 17:30:31 EDT 2016


On Thu, Mar 17, 2016 at 7:55 AM, Terry Reedy <tjreedy at udel.edu> wrote:
> On 3/16/2016 3:08 PM, Chris Angelico wrote:
>>
>> On Thu, Mar 17, 2016 at 5:53 AM, Ben Finney <ben+python at benfinney.id.au>
>> wrote:
>>>>
>>>> For example a hint that "0" does work for the given argument.
>>>
>>>
>>> I suggest: “zero-padding only allowed for numeric types, not 'str'”.
>>
>>
>> That's very slightly misleading too; zero padding is perfectly legal
>> as long as you force the alignment:
>>
>>>>> "{:>05}".format("1")
>>
>> '00001'
>>>>>
>>>>> "{:>05}".format("2")
>>
>> '00002'
>>>>>
>>>>> "{:>05}".format("-3")
>>
>> '000-3'
>>
>> Though as the last example shows, this doesn't properly handle signs
>> ("-0003" would be preferred).
>
>
> Sign-aware 0 padding is only for numeric types.  '-3' is a string, no
> different from 'ab'.

Right, and that's not changing. But there are a lot of situations in
which '=' and '>' will be absolutely identical (eg formatting a
sequence number, starting from zero or one and moving up from there),
and it would be misleading to tell people that zero-padding isn't an
option just because of a technical difference.

ChrisA



More information about the Python-list mailing list