To create and write to a file in python3 f = open(filename, "x+") f = open(filename, 'w') f.write(content) f.close()