Ron Adam wrote:
>> I've been re-reading the PEP, in an effort to make sure everything is
>> working. I realized that these tests should not pass. The PEP says
>> that "Format specifiers can themselves contain replacement fields".
>> The tests above have replacement fields in the field name, which is
>> not allowed. I'm going to remove this functionality.
>>
>> I believe the intent is to support a replacement for:
>> "%.*s" % (4, 'how now brown cow')
>>
>> Which would be:
>> "{0:.{1}}".format('how now brown cow', 4)
>>
>> For this, there's no need for replacement on field name. I've taken
>> it out of the code, and made these tests in to errors.
>
> I think it should work myself, but it could be added back in later if
> there is a need to.
>
>
> I'm still concerned about the choice of {{ and }} as escaped brackets.
>
> What does the following do?
>
>
> "{0:{{^{1}}".format('Python', '12')
>>> "{0:{{^{1}}".format('Python', '12')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: unterminated replacement field
But:
>>> "{0:^{1}}".format('Python', '12')
' Python '
> "{{{0:{{^{1}}}}".format('Python', '12')
>>> "{{{0:{{^{1}}}}".format('Python', '12')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Unknown conversion type }
But,
>>> "{{{0:^{1}}".format('Python', '12')
'{ Python '
> class ShowSpec(str):
>
> return spec
>
> ShowSpec("{0:{{{1}}}}").format('abc', 'xyz')
>
>>> ShowSpec("{0:{{{1}}}}").format('abc', 'xyz')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Invalid conversion specification
I think you mean:
ShowSpec("{0:{1}}").format('abc', 'xyz')
But I have some error with that. I'm looking into it.
> "{0}".format('{value:{{^{width}}', width='10', value='Python')
>>> "{0}".format('{value:{{^{width}}', width='10', value='Python')
'{value:{{^{width}}'
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com