Eric V. Smith <e...@trueblade.com> 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 "<stdin>", line 1, in <module> ValueError: unmatched '{' in format spec And your second example: >>> '{:{>10d'.format(5) Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 <rep...@bugs.python.org> <https://bugs.python.org/issue44146> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com