This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: reading scientific notation using d instead of e on max osx
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, mark.dickinson, ricitron, ronaldoussoren
Priority: normal Keywords:

Created on 2010-02-12 18:47 by ricitron, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (10)
msg99281 - (view) Author: (ricitron) Date: 2010-02-12 18:47
I would like to be able to read in data that uses scientific notation with a D instead of an E. This is possible on windows and other builds, but not on Mac OSX. 

example:
float('1.23D+04')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for float(): 1.23D+04
msg99282 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2010-02-12 19:39
str->float conversions have been reworked in 2.7 and 3.1. The 'D' exponent will not on any platform starting with those versions.

So, this would be a non-platform specific feature request.
msg99283 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2010-02-12 19:49
That was supposed to say:

The 'D' exponent will not work on any platform starting with those versions.
msg99284 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-02-12 19:55
Out of curiosity, where are your data coming from?

For Python, this seems like a needless complication.  It should be simple enough to replace the 'D's with 'E's prior to passing the strings to float.

I notice that some varieties of Lisp and Scheme use 's', 'f', 'd', 'l' as the exponent marker for floats of different precisions (short, single, double, long double).  But Python only has one precision of float.
msg99285 - (view) Author: (ricitron) Date: 2010-02-12 20:05
I am running python 2.5.4. While it works on linux and windows, it does not work on mac. 

Fortran doubles are output using the D notation. If I am importing a large amount of data, I would rather not do a search and replace every time before reading in the data.
msg99287 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-02-12 20:46
Sorry, I'm -1 on this:  outside Fortran, using 'E' for the exponent marker seems to be near universal.  It just doesn't seem worth adding the extra complication to the Python code, or going through all the various places that expect an 'e' (float literals in Python source, inputs to the float function, Decimal and Fraction inputs, complex numbers, etc.) and trying to decide whether 'd' should be supported there too.

Even in Fortran, isn't it normal to output floats and doubles using the 'E' format specifier?
msg99288 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-02-12 20:49
> I would rather not do a search and replace every time before reading in > the data.

There's no need to do a search and replace *before* reading the data:  read the data first, then have Python do the replace for you before passing each string to float:

>>> t = string.maketrans('d', 'e')
>>> '-14.235d+03'.translate(t)
'-14.235e+03'
msg99289 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2010-02-12 21:11
Unless and until we implement 'd' exponents, we should add a test to make sure they don't work. That they ever worked on any platform was a surprise. 
--
Eric.
msg99291 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-02-12 21:19
Done in r78166 (trunk), r78167 (py3k).
msg99305 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2010-02-13 03:54
I'm -1 on this, too. Closing.
History
Date User Action Args
2022-04-11 14:56:57adminsetgithub: 52167
2010-02-13 03:54:14eric.smithsetstatus: open -> closed
resolution: rejected
messages: + msg99305

stage: resolved
2010-02-12 21:19:07mark.dickinsonsetmessages: + msg99291
2010-02-12 21:11:50eric.smithsetmessages: + msg99289
title: reading scientific notation using d instead of e on max osx -> reading scientific notation using d instead of e on max osx
2010-02-12 20:49:34mark.dickinsonsetmessages: + msg99288
2010-02-12 20:46:18mark.dickinsonsetmessages: + msg99287
2010-02-12 20:05:25ricitronsetmessages: + msg99285
2010-02-12 19:55:08mark.dickinsonsetmessages: + msg99284
2010-02-12 19:49:49eric.smithsetmessages: + msg99283
2010-02-12 19:39:11eric.smithsetversions: + Python 2.7, Python 3.2, - Python 2.5
nosy: + mark.dickinson, eric.smith

messages: + msg99282

assignee: ronaldoussoren ->
components: + Interpreter Core, - macOS
2010-02-12 18:47:35ricitroncreate