Prev: pyqt4 vs pygtk2 vs pyjamas (was: GUIs - A Modest Proposal)
Next: How to print via python on windows
From: Nathan Huesken on 14 Jun 2010 10:57 Hi, tempfile.mkstemp returns a file name and a file descriptor (as returned by os.open). Can I somehow convert this descriptor to a file object? Thanks! Nathan
From: Thomas Jollans on 14 Jun 2010 11:07 On 06/14/2010 04:57 PM, Nathan Huesken wrote: > Hi, > > tempfile.mkstemp returns a file name and a file descriptor (as returned > by os.open). Can I somehow convert this descriptor to a file object? the builtin open function should work. http://docs.python.org/py3k/library/functions.html#open Also, it's probably better to just use a tempfile.TemporaryFile or tempfile.NamedTemporaryFile instead of directly using mkstemp. -- Thomas
From: Robert Kern on 14 Jun 2010 15:05 On 6/14/10 9:57 AM, Nathan Huesken wrote: > Hi, > > tempfile.mkstemp returns a file name and a file descriptor (as returned > by os.open). Can I somehow convert this descriptor to a file object? Thomas Jollans' advice is likely best, but to answer your specific question, use os.fdopen() to make a file object corresponding to the file descriptor. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
From: Gabriel Genellina on 15 Jun 2010 03:34 En Mon, 14 Jun 2010 11:57:20 -0300, Nathan Huesken <python(a)lonely-star.org> escribi�: > tempfile.mkstemp returns a file name and a file descriptor (as returned > by os.open). Can I somehow convert this descriptor to a file object? py> import os py> help(os.fdopen) Help on built-in function fdopen in module nt: fdopen(...) fdopen(fd [, mode='r' [, bufsize]]) -> file_object Return an open file object connected to a file descriptor. -- Gabriel Genellina
|
Pages: 1 Prev: pyqt4 vs pygtk2 vs pyjamas (was: GUIs - A Modest Proposal) Next: How to print via python on windows |