tempfile.mkstemp and os.fdopen

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Aug 29 00:27:02 EDT 2007


On 28 ago, 22:21, billiejoex <gne... at gmail.com> wrote:

> Another question: I have to open file for writing ('wb') but I noticed
> that both tempfile.mkstemp() and os.fdopen() accept a "mode" argument.
> It's not clear *when* do I have to specify such mode. When using
> tempfile.mkstemp?
>
> Moreover, what happens if I specify "text" mode when using mkstemp and
> "binary" mode when using fdopen?
>
> PS - I think that tempfile.mkstemp docstring should be enhanced to
> cover such and other questions (e.g. I find reasonable that every user
> using tempfile.mkstemp() should use also os.fdopen() in conjunction
> but this isn't mentioned).

As someone already suggested, why don't you use TemporaryFile or
NamedTemporaryFile and avoid such problems?

--
Gabriel Genellina




More information about the Python-list mailing list