[Numpy-discussion] fromfile and tofile access with a tempfile.TemporaryFile()

Lisandro Dalcin dalcinl at gmail.com
Tue Dec 12 18:31:33 EST 2006


>
> It seems to me that the temporary file mechanism on Windows is a little
> odd.
>

Indeed, looking at sources, the posix version uses the mkstemp/unlink
idiom.. but in win it uses a bit of hackery. It seems opened files
cannot be unlinked.


if _os.name != 'posix' or _os.sys.platform == 'cygwin':
    # On non-POSIX and Cygwin systems, assume that we cannot unlink a file
    # while it is open.
    TemporaryFile = NamedTemporaryFile

else:
    def TemporaryFile(mode='w+b', bufsize=-1, suffix="",
                      prefix=template, dir=None):
       ............
        (fd, name) = _mkstemp_inner(dir, prefix, suffix, flags)
        try:
            _os.unlink(name)
            return _os.fdopen(fd, mode, bufsize)
        except:
            _os.close(fd)
            raise



-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594



More information about the NumPy-Discussion mailing list