PyUnicode_FromFormat()
and several other functions like PyErr_Format()
support a subset of printf-like formatting with some extensions to support Python objects. It is a very limited subset, for example %x
is supported, but %lx
and %X
are not.
I propose to add support of more printf features:
o
(octal) and X
(uppercase hexadecimal).j
(intmax_t) and t
(ptrdiff_t).%ls
and %lV
).*
.-
(left alignment).The following standard features are intentionally not implemented:
#
,
(a space) and +
. #
is ambiguous for octals: should we use prefix 0
(as in C) or 0o
(as in Python)? The latter two flags are just rarely used (I initially implemented the support of them, but then removed, it is not worth).h
(signed char
and unsigned char
) and hh
(short
and unsigned short
). Values of these types are automatically promoted to int
or unsigned int
, and you can use explicit conversion to int
or unsigned int
in case of ambiguity.%lc
. Since %c
already accepts integers outside of the range 0-255, and the difference between int
and wint_t
is subtle, I am not sure that that there is any value of supporting it.%n
.%c
and %p
.Unlike to printf, unsupported modifiers (like %lc
or %10c
) raise SystemError instead of be silently ignored. It will allow to add new features without breaking accidentally working code.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4