I want to run a function over a loop and I want to store the outputs in different files, such that the filename contains the loop variable. Here is an example
Try this:
for i in xrange(10): with open('file_{0}.dat'.format(i),'w') as f: f.write(str(func(i)))