Python Forum
module 'os' has no attribute 'tmpfile' - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: module 'os' has no attribute 'tmpfile' (/thread-27575.html)



module 'os' has no attribute 'tmpfile' - whois1230 - Jun-11-2020

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'



RE: module 'os' has no attribute 'tmpfile' - menator01 - Jun-11-2020

I could be wrong but, the error is saying the os has no method called tmpfile


RE: module 'os' has no attribute 'tmpfile' - buran - Jun-11-2020

probably you want to look at tempfile module


RE: module 'os' has no attribute 'tmpfile' - ndc85430 - Jun-12-2020

Why did you think there was a tmpfile function in the os module?