[Numpy-discussion] Implementing __format__
Christopher Barker
Chris.Barker at noaa.gov
Mon Nov 15 14:44:12 EST 2010
On 11/15/10 11:35 AM, Pauli Virtanen wrote:
> One can argue that this is a bug in Python or Numpy:
>
> "%d" % numpy.int16(1)
>
> "{0:d}".format(numpy.int16(1))
> To make it work via changes in Numpy: scalars should implement a
> __format__ method. Two choices: either we parse the formatting string
> ourselves, or forward formatting to Python. The PITA in implementing this
> is in parsing the format string.
>
> Doing formatting ourselves would allow e.g. formatting of long doubles
> properly, which cannot be done via the %-syntax.
Also good handling of NaN, which there is other custom code in numpy to
handle better than python (in string parsing, anyway).
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
More information about the NumPy-Discussion
mailing list