I looked at python2.5.1 source code. I noticed that, in Objects/stringobject.c around line 4684, long type is exceptionally handled, which is hack, and everything else falls to formatint. This explains why explicit converting to long before formatting fixes the problem. I made a patch but this is a hack on a hack. I expect Python3000 won't have such problem as they unify int and long.
Thanks Kenji Noguchi --- stringobject.c.org 2007-06-21 13:57:54.745877000 -0700 +++ stringobject.c 2007-06-21 13:59:19.576646000 -0700 @@ -4684,6 +4684,15 @@ case 'X': if (c == 'i') c = 'd'; + /* try to convert objects to number*/ + PyNumberMethods *nb; + if ((nb = v->ob_type->tp_as_number) && + nb->nb_int) { + v = (*nb->nb_int) (v); + if(v == NULL) + goto error; + } + if (PyLong_Check(v)) { int ilen; temp = _PyString_FormatLong(v, flags, 2007/6/21, Kenji Noguchi <[EMAIL PROTECTED]>: > 2007/6/20, Gabriel Genellina <[EMAIL PROTECTED]>: > > It is a bug, at least for me, and I have half of a patch addressing it. As > > a workaround, convert explicitely to long before formatting. > > I'm interested in your patch. What's the other half still missing? -- http://mail.python.org/mailman/listinfo/python-list