'complex' function with string argument.

Terry Reedy tjreedy at udel.edu
Mon Mar 17 23:06:50 CET 2014


On 3/17/2014 1:55 PM, Mark Dickinson wrote:
> Jayanth Koushik <jnkoushik <at> gmail.com> writes:
>
>> "Note: When converting from a string, the string must not contain whitespace
>> around the central + or - operator. For example, complex('1+2j') is fine, but
>> complex('1 + 2j') raises ValueError."
>>
>> Why is this so?
>
> See http://bugs.python.org/issue9574 for a bit more context.  To begin with,
> it's not at all clear what *should* be allowed.  If "1 + 2j" is valid, what
> about "+ 2j"?  How about "+ 2"?  What about things like "+1.0 + -2.3j"?
> Ultimately, I closed that issue because the proposed change seemed like
> unnecessary code churn, and there wasn't a clear consensus that the change was
> desirable (or even what that change should be).  If it ain't broke, etc.

I was not nosy on that issue, but  I agree with 'as is', along with no 
space in Franction("1/2"). Mathematicians genearally write both without 
spaces.

-- 
Terry Jan Reedy




More information about the Python-list mailing list