Python Forum

Full Version: module 'os' has no attribute 'tmpfile'
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I wrote the following program and tried to execute it:
#!/usr/bin/python3.8
import os
# The file has no directory entries associated with it and will be
# deleted automatically once there are no file descriptors.
tmpfile = os.tmpfile()
tmpfile.write('Temporary newfile is here......')
tmpfile.seek(0)

print (tmpfile.read())
tmpfile.close
but I'm getting an error:
Error:
Traceback (most recent call last): File "/home/user/Desktop/Programming/Python/Os tmpfile method.py", line 5, in <module> tmpfile = os.tmpfile() AttributeError: module 'os' has no attribute 'tmpfile'
I could be wrong but, the error is saying the os has no method called tmpfile
probably you want to look at tempfile module
Why did you think there was a tmpfile function in the os module?