Replace weird error message?

Terry Reedy tjreedy at udel.edu
Wed Mar 16 16:55:57 EDT 2016


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'.

-- 
Terry Jan Reedy





More information about the Python-list mailing list