[issue5812] Fraction('1e6') should be valid.

Mark Dickinson report at bugs.python.org
Wed Apr 22 12:04:27 CEST 2009


New submission from Mark Dickinson <dickinsm at gmail.com>:

When the Fractions module was first added to Python, it was decided that
when constructing from a string, decimal strings should be allowed, but
not those including an exponent.  For example, Fraction('1.1') is
currently valid, but Fraction('1.1e6') is not.

I think exponents should be permitted, for a couple of reasons:

(1) consistency:  there's a clearly-defined notion of a numeric string
of the form ([sign] integer_part [fractional_part] [exponent]);  the
float and Decimal constructors both accept all numeric strings. 
Fraction currently accepts some, but not all of these.

(2) Easy interactions with floats:  with this addition, a Fraction can
always be constructed from the str() or repr() of a finite float or
finite Decimal;  without it, only some of those strings can be converted.

(3) Ease of parsing files containing numeric strings.

(4) It's a very simple change!  See attached patch.

Jeffrey, any thoughts?

----------
assignee: marketdickinson
components: Library (Lib)
files: fraction_from_exp.patch
keywords: patch
messages: 86283
nosy: jyasskin, marketdickinson
priority: normal
severity: normal
stage: patch review
status: open
title: Fraction('1e6') should be valid.
type: feature request
versions: Python 2.7, Python 3.1
Added file: http://bugs.python.org/file13735/fraction_from_exp.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5812>
_______________________________________


More information about the Python-bugs-list mailing list