You can use any expression as the first argument to open().
So all can be done into the loop:
So all can be done into the loop:
for num in range(300): with open('ctrlptdata_{}'.format(num), 'w') as fp: fp.write(num)If you have 300 files