473,320 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Is this a bug in the windows tempfile.py?

import tempfile
import types
print isinstance(tempfile.TemporaryFile(), types.FileType)
Prints False on Windows and True on linux or any other posix system.
The reason for the difference is on posix systems TemporaryFile returns
an actual file (the result of os.fdopen()) and on windows,
TemporaryFile returns a file wrapper which forwards getattr calls to
the underlying file.

The wrapper used on windows provides an alternative close method that
deletes the temporary file.
Should the wrapper inherit types.FileType?

Jonathan.

Jul 18 '05 #1
1 1732
Jonathan Wright wrote:
Should the wrapper inherit types.FileType?


No. Code assuming that the result from tempfile.TemporaryFile
is a file object is broken - you are only guaranteed a
file-like object. Applications should not use isinstance to
determine whether something is a file-like object.

Regards,
Martin
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Justin | last post by:
Hi. I have a perl script that can be run at the command line to take some HTML and do something filtering with it. What I want to do is use it from within PHP (run the script on a var, eg: echo...
2
by: marco | last post by:
Hello, I having a problem creating directories with Python 2.3.4 (compiled with gcc 3.2.2, under Linux 2.4.20-31.9). I'm writing a plugin which works in the following way: GUI --...
0
by: Leo Breebaart | last post by:
On MS Windows, I am trying to find out a good default location to save some temporary files. The tempfile module seemed to have exactly what I wanted: >>> import tempfile >>>...
5
by: TazCoder | last post by:
I need to figure out an algorithm to convert any file, into it's hex representation in order to print out that file in windows forms. I do not want byteviewer in this and that is why it is...
5
by: Lee Harr | last post by:
Is there any other reason to use a named tempfile other than to be able to open it again? I am trying to understand this section of the documentation regarding NamedTemporaryFile: """ Whether...
3
by: noisefree | last post by:
Hello, I have a problem on an application I am developing: This C# Windows Application calls a C# Web Service, which it uses the SourceSafeTypeLib DLL to interact with Visual Source Safe 6. ...
6
by: James T. Dennis | last post by:
Tonight I discovered something odd in the __doc__ for tempfile as shipped with Python 2.4.4 and 2.5: it says: This module also provides some data items to the user: TMP_MAX - maximum number...
9
by: billiejoex | last post by:
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,...
7
by: byte8bits | last post by:
Wondering if someone would help me to better understand tempfile. I attempt to create a tempfile, write to it, read it, but it is not behaving as I expect. Any tips? <open file '<fdopen>', mode...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.