f = tempfile.NamedTemporaryFile(delete=False)
f.name
f.write('Hello world')
f.close()
os.rename(f.name, 'C:\\foo.txt')
if os.path.exists('C:\\foo.txt'):
    pass
How do I create a file in python without overwriting an existing file