Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import os
- import tempfile
- print 'Building a filename with PID:'
- filename = '/tmp/guess_my_name.%s.txt' % os.getpid()
- temp = open(filename, 'w+b')
- try:
- print 'temp:'
- print ' ', temp
- print 'temp.name:'
- print ' ', temp.name
- finally:
- temp.close()
- # Clean up the temp file
- os.remove(filename)
- print
- print 'TemporaryFile:'
- temp = tempfile.TemporaryFile()
- try:
- print 'temp:'
- print ' ', temp
- print 'temp.name:'
- print ' ', temp.name
- finally:
- # Automatically cleans up the file
- temp.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement