Re: print and long ints...

Tim Peters (tim@ksr.com)
Thu, 10 Mar 94 13:48:18 EST

> Why can't I use the '%' modifier on a print statement AND use a LONG
> as the value passed in?

I'm not sure, but it's been that way from the start. E.g., my old Dates
module returns a date's string representation via

return '%.3s %2d %.3s ' % (
self.weekday(),
self.day,
_MONTH_NAMES[self.month-1] ) + `self.year`

because self.year may be a long (so can't be converted as part of the '%'
operation).

I bet Steve's right, that it's because libc's sprintf doesn't know about
Python's long ints.

Note that

return '%.3s %2d %.3s %s' % (
self.weekday(),
self.day,
_MONTH_NAMES[self.month-1],
`self.year` )

would have worked in the above, which may or may not strike you as cleaner.

minor-inelegance-ly y'rs - tim

Tim Peters tim@ksr.com
not speaking for Kendall Square Research Corp