I want to read from a file a set of complex numbers into an array,using Python. I know how to do it only for integers. I tried this,but when I run it ,it says: complex() arg is a malformed string. How can I do to read complex numbers? I just started to learn Python.
f=open("file.txt","r+")
array=[]
for line in f:
line=line.split()
if line:
line=[complex(i) for i in line]
My file contains only complex numbers:
1+i
1-i
1
2
-3