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
Concatenate the i variable to a string as follows:
i
f = open("file_"+str(i)+".dat","w")
OR
f = open("file_"+`i`+".dat","w") # (`i`) - These are backticks, not the quotes.
See here for other techniques available.