import tempfile with tempfile.NamedTemporaryFile(delete=False) as temp: temp.write(b'Hello, World!') print(temp.name) # Prints the file name
import tempfile with tempfile.NamedTemporaryFile() as temp: fd = temp.fileno() # Get file descriptor print(fd) # Print the file descriptorIn this example, we have created a temporary file using the "NamedTemporaryFile" function and opened it using a "with" statement. We have accessed the file descriptor using the "fileno" method and printed it on the console. Both of these examples use the "tempfile" module in Python.