Home

On Aug 28, 7:55 pm, billiejoex <gne...@gmail.com> 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))

previous
next

Re: How to find out if the interpreter is a debug build?
Re: Problem with extremely small real number
Re: Unary plus integral promotion
Re: What is the solution..?
Re: how to reach an arbitrary index in a std::list
Akogo
Pajacyk
Fundacja Sloneczko
Mimo Wszystko
Fundacja Iskierka