git @ Cat's Eye Technologies Dipple / master python / mkstemp.py
master

Tree @master (Download .tar.gz)

mkstemp.py @masterraw · history · blame

#!/usr/bin/env python

# A gotcha with mkstemp: see e.g. https://web.archive.org/web/20120510002701/http://www.logilab.org/blogentry/17873

# Note that this script contains code from a blog post distributed under
# the Creative Commons-Attribution-ShareAlike 2.0 license, which is not
# a generally recommended license for open-source redistribution of
# source code (but you can read and learn from this source code.)

# SPDX-FileCopyrightText: 2010 Logilab.org
#
# SPDX-License-Identifier: CC-BY-SA-2.0


import os
from tempfile import mkstemp

fd, filename = mkstemp()
with open(filename, 'w') as file:
    file.write('hello')
    file.close()
os.close(fd) # if you do not do this, you will leak filehandles
print "wrote out %s" % filename