SHARE
TWEET

Untitled

a guest Apr 20th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2. import tempfile
  3.  
  4.  
  5. file_descriptor, file_path = tempfile.mkstemp(suffix='.tmp')
  6.  
  7. # You can convert the low level file_descriptor to a normal open file using fdopen
  8. with os.fdopen(file_descriptor, 'w') as open_file:
  9.     open_file.write('hello')
  10.  
  11. # OR without the 'with'
  12. open_file = os.fdopen(file_descriptor, 'w')
  13. open_file.write('hello')
  14. open_file.close()
  15.  
  16. # OR without the open low level file_descriptor
  17. os.close(file_descriptor)
  18. open_file = open(file_path, 'w')
  19. open_file.write('hello')
  20. open_file.close()
  21.  
  22.  
  23. # You are responsibile for deleting your temp file
  24. os.unlink(file_path)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top