[issue2802] str.format() :n integer output

Mark Dickinson report at bugs.python.org
Fri May 9 16:23:29 CEST 2008


Mark Dickinson <dickinsm at gmail.com> added the comment:

> I think that n should stay the same for floats, but for integers should
> never switch to g, but just use as many separators as needed.

I agree with this, in principle.  It might be some work to implement, 
though:  for floats, Python gets to use the OS-supplied formatting 
functions.  Indeed, it looks as though all that happens here is that the 
integer is converted to a float before formatting:

>>> print("{0:n} ".format(10**400), end="")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: Python int too large to convert to C double

For integers, we'd have to roll our own code. I had similar problems 
trying to implement the 'n' format code for Decimal;  in the end I just 
gave up and left it unimplemented.  Maybe using 'n' for an integer should 
just raise an exception, for now?

Eric, what do you think?

----------
assignee:  -> eric.smith
nosy: +eric.smith, marketdickinson
priority:  -> normal

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2802>
__________________________________


More information about the Python-bugs-list mailing list