On Aug 28, 7:55 pm, billiejoex <[EMAIL PROTECTED]> wrote:
> Hi there.
> I'm trying to generate a brand new file with a unique name by using
> tempfile.mkstemp().
> In conjunction I used os.fdopen() to get a wrapper around file
> properties (write & read methods, and so on...) but 'name' attribute
> does not contain the correct file name. Why?
>
import tempfile, os
class TempFile(object):
def __init__(self, fd, fname):
self._fileobj = os.fdopen(fd, 'w+b')
self.name = fname
def __getattr__(self, attr):
return getattr(self._fileobj, attr)
def mktempfile(dir=None, suffix='.tmp'):
return TempFile(*tempfile.mkstemp(dir=dir, suffix=suffix))
--
http://mail.python.org/mailman/listinfo/python-list