Apr-04-2021, 02:49 AM
The below code gives an error on the line: tfp = open(path, "w+t")
Anyone know why?
Anyone know why?
Error:Exception has occurred: NotADirectoryError
[WinError 267] The directory name is invalid: 'C:\\Users\\gener\\AppData\\Local\\Temp\\tmp99c64lys\\tempfile.txt'
File "C:\Users\gener\OneDrive\My Documents\Python Programming\run.py", line 10, in <module>
print(tfp.read())import os
import tempfile
# create a temporary directory using the TemporaryDirectory class
with tempfile.TemporaryDirectory() as tdp:
path = os.path.join(tdp, "tempfile.txt")
tfp = open(path, "w+t")
tfp.write("This is a temp file in temp dir")
tfp.seek(0)
print(tfp.read())
