I was wondering if there is a way to write a template to file inside of a for loop. The code below is an example of what I have written so far. The variable inside of the open function equals 'python.py'.
with open(filename, 'w') as fout:
x = 0
for x in range(5):
fout.write(""" def function_number{}(): \n
""".format(x))
Here is what I am expecting to happen
def function_number0():
def function_number1():
def function_number2():
def function_number3():
def function_number4():
Here is the output I receive
def function_number0():
def function_number1():
def function_number2():
def function_number3():
def function_number4():
How can I restructure my code to get the desired output?