New submission from Xiang Zhang:

Although declared *exactly equivalent* to printf in the doc, 
PyUnicode_FromFormat could generate different result from printf with the same 

For example:

from ctypes import pythonapi, py_object, c_int
f = getattr(pythonapi, 'PyUnicode_FromFormat')
f.restype = py_object
f(b'%010.5d', c_int(100))

while printf outputs:

printf("%010.5d\n", 100);

I use both gcc and clang to compile and get the same result. gcc gives me a 

warning: '0' flag ignored with precision and ā€˜%dā€™ gnu_printf format

I am not sure this should be fixed. It seems the change could break backwards 

components: Interpreter Core
messages: 278467
nosy: haypo, serhiy.storchaka, xiang.zhang
priority: normal
severity: normal
status: open
title: PyUnicode_FromFromat interger format handling different from printf 
about zeropad
type: behavior
versions: Python 3.5, Python 3.6, Python 3.7

Python tracker <>
Python-bugs-list mailing list

Reply via email to