Currently format strings (and f-string expressions) support three
conversions: !s -- str, !r -- repr and !a for ascii.

I propose to add support of additional conversions: for int, float and
operator.index. It will help to convert automatically printf-like format
strings to f-string expressions: %d, %i, %u -- use int, %f -- use float,
%o, %x -- use operator.index.

For float the conversion letter is obvious -- !f. But I am not sure for
what !i should be used, for int or operator.index. If make it
operator.index, then !d perhaps should be used for int. If make it int,
then !I perhaps should be used for operator.index. Or vice verse?

Also I propose to support applying multiple conversions for the same
item. It is common when you output a path or URL object as quoted string
with all escaping, because in general it can contain special or
non-printable characters. Currently I write f"path = {repr(str(path))}"
or f"path = {str(path)!r}", but want to write f"path = {path!s!r}".

Do we need support of more standard conversions? Do we want to support
custom conversions (registered globally as encodings and error
handlers). re.escape, html.escape and shlex.quote could be very useful
in some applications.

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/3AALXB6A7EN6UY635MF5O2SFHZVFA5NM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to