Here the code:
import itertools
# import list from file
a = [line.strip() for line in open("real.txt", 'r')]
b = [line.strip() for line in open("imag.txt", 'r')]
# create file contain restore informations
f = open("restore.txt","w+")
loop = 0
try:
for r in itertools.product(a,b):
loop +=1
print "processing : "+ r[1] + ": "+ r[0] + " ("+str(loop)+")"
except Exception, e:
print str(e)
f.write("iterazions seccession: " +str(loop)+"\n")
f.write("real number : " +r[1]+"\n")
f.write("imaginary unit: " + r[0]+ "\n")
example output
processing: 1 : 1i (1)
processing: 1 : 2i (2)
processing: 1 : 3i (3)
processing: 1 : 4i (4)
...
processing: 2000 : 174i (348000)
processing: 2000 : 175i (348001)
...and so forth
(it does all combinations of two lists)
the question is if an error stop the iteration, there's a way to restart the script from last iteration without start from scratch? I try saving the last value in a file but I do not know how to use it.
p.s. I know the cmath function for complex number but I’m more interested to restore issue
more specific
if an error stop the iteration at: processing: 2000 : 175i (348001) there is a way to restart the script from 2000 : 175i (348001) iteration?