'complex' function with string argument.

Mark H Harris harrismh777 at gmail.com
Mon Mar 17 19:20:51 CET 2014

On 3/17/14 12:03 PM, Chris Angelico wrote:
>>>> ast.dump(ast.parse("complex( 3   +2j  )"))
> "Module(body=[Expr(value=Call(func=Name(id='complex', ctx=Load()),
> args=[BinOp(left=Num(n=3), op=Add(), right=Num(n=2j))], keywords=[],
> starargs=None, kwargs=None))])"
> The sole argument to complex() is an expression which sums the integer
> 3 and the imaginary 2j, which results in the complex (3+2j), which
> complex() looks at and returns unchanged. And that's what you see.

~very nice.

Ok, going along with Mark's comment about this bug report:

> See http://bugs.python.org/issue9574

This string  '3  +2j'  should probably be ok from the complex() string
constructor standpoint, right?

I mean, there might be more than one constructor for string, mighten-it?


More information about the Python-list mailing list