Advertisement
rfmonk

tempfile_TemporaryFile.py

Jan 28th, 2014
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. import os
  5. import tempfile
  6.  
  7. print 'Building a filename with PID:'
  8. filename = '/tmp/guess_my_name.%s.txt' % os.getpid()
  9. temp = open(filename, 'w+b')
  10. try:
  11.     print 'temp:'
  12.     print ' ', temp
  13.     print 'temp.name:'
  14.     print ' ', temp.name
  15. finally:
  16.     temp.close()
  17.     # Clean up the temp file
  18.     os.remove(filename)
  19.  
  20. print
  21. print 'TemporaryFile:'
  22. temp = tempfile.TemporaryFile()
  23. try:
  24.     print 'temp:'
  25.     print ' ', temp
  26.     print 'temp.name:'
  27.     print ' ', temp.name
  28. finally:
  29.     # Automatically cleans up the file
  30.     temp.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement