[Python-3000] PEP 3101 Updated

Eric Smith eric+python-dev at trueblade.com
Thu Aug 23 02:00:57 CEST 2007


Guido van Rossum wrote:
> On 8/22/07, Eric Smith <eric+python-dev at trueblade.com> wrote:
>> James Thiele wrote:
>>> In the section "Explicit Conversion Flag" of PEP 3101 it says:
>>>
>>> Currently, two explicit conversion flags are recognized:
>>>
>>>         !r - convert the value to a string using repr().
>>>         !s - convert the value to a string using str().
>>> --
>>> It does not say what action is taken if an unrecognized explicit
>>> conversion flag is found.
>> My implementation raises a ValueError, which I think is the desired
>> behavior:
>>
>>  >>> "{0!x}".format(1)
>> Traceback (most recent call last):
>>    File "<stdin>", line 1, in <module>
>> ValueError: Unknown converion specifier x
> 
> You raise ValueErrors for other errors with the format, right? If
> there's a reason to be more lenient, the best approach would probably
> be to interpret it as !r.

Yes, ValueError gets raised for other errors with the format specifiers. 
  My concern is that if we silently treat unknown conversion specifiers 
as !r, we can't add other specifiers in the future without breaking 
existing code.



More information about the Python-3000 mailing list