'complex' function with string argument.

Jayanth Koushik jnkoushik at gmail.com
Sat Mar 15 12:26:21 EDT 2014


Hi everyone!

This is regarding the inbuilt 'complex' function. The python docs say:
"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? Why can't spaces be allowed everywhere and simply ignored? I went through the source and it did not seem like this was an internal requirement, so it seems like a design choice. Is there any reason why spaces in the middle would be a problem?

Jayanth Koushik



More information about the Python-list mailing list