import os gg = {} i = 0 while True: gg[i] = open(os.path.join(os.getcwd(),'lol%s.txt'%i),'w+') gg[i].write('hello!') gg[i].close() i = i+1