from tempfile import TemporaryFile # Create a temporary file and write some data to it fp = TemporaryFile("w+t") fp.write("Hola!") # Go back to the beginning and read data from file fp.seek(0) data = fp.read() print(data) # Close the file, after which it will be removed fp.close() # otra forma with TemporaryFile("w+t") as fp: fp.write("Otro") fp.seek(0) data = fp.read() print(data)