[issue44146] Format string fill not handling brace char

2021-06-09 Thread Martin Panter


Martin Panter  added the comment:

Another workaround:

>>> '{:{brace}>10d}'.format(5, brace='{')
'{5'

--
nosy: +martin.panter

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44146] Format string fill not handling brace char

2021-05-19 Thread Eric V. Smith


Eric V. Smith  added the comment:

Since this is working as designed, I'm going to close it.

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44146] Format string fill not handling brace char

2021-05-16 Thread Eric V. Smith


Eric V. Smith  added the comment:

In the future, if you get an error, please tell us what the error is. It makes 
responding to bugs easier.

'{::>10d'.format(5)
Gives me an error with 3.10:

>>> '{::>10d'.format(5)
Traceback (most recent call last):
  File "", line 1, in 
ValueError: unmatched '{' in format spec

And your second example:

>>> '{:{>10d'.format(5)
Traceback (most recent call last):
  File "", line 1, in 
ValueError: unmatched '{' in format spec

This root cause of treating left braces as special is because braces can nest. 
I don't think there's any way of doing what you want, just like you can't use a 
closing brace as part of a format spec while using str.format() or f-strings.

width=10
>>> f'{5:{width}}'
' 5'
>>> '{0:{1}}'.format(5, width)
' 5'


If you really want to use braces in the format spec, you should use format, 
which does not parse braces:

>>> format(5, '{>10d')
'{5'

--
nosy: +eric.smith

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44146] Format string fill not handling brace char

2021-05-16 Thread svs


New submission from svs :

Format strings and f-strings don't seem to handle brace characters as a fill 
character.

E.g.

'{::>10d'.format(5) => ':5"  (as expected)

'{:{>10d'.format(5) => error. Expect: '{5"

trying {{ escape does not work either.
'{:{{>10d'.format(5) => error.

The same goes for '}'. f-strings have a similar issue.

--
components: Interpreter Core
messages: 393735
nosy: snegavs
priority: normal
severity: normal
status: open
title: Format string fill not handling brace char
type: behavior
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com