[ python-Bugs-1615275 ] tempile.TemporaryFile differences between linux and windows
SourceForge.net
noreply at sourceforge.net
Wed Mar 28 16:43:56 CEST 2007
Bugs item #1615275, was opened at 2006-12-13 16:20
Message generated for change (Comment added) made by draghuram
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1615275&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Extension Modules
Group: Platform-specific
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: hirzel (hirzel)
Assigned to: Nobody/Anonymous (nobody)
Summary: tempile.TemporaryFile differences between linux and windows
Initial Comment:
This bug came up when trying to write a numpy array to a tempfile.TemporaryFile() using the numpy 'tofile' method on windows using python 2.4.
with a numpy array 'a', and a TemporaryFile 'f',
on windows:
>>> a.tofile(f)
throws an IOError, where on Linux it does not.
On windows, you must use a.tofile(f.file)
The cause of this difference is that in windows, tempfile.TemporaryFile() returns <type 'instance'> that has a 'file' attribute of <type 'file'>, whereas in linux tempfile.TemporaryFile() returns <type 'file'> and there is no 'file' attribute.
Ideally, the windows version would align with linux, and the module documentation and TemporaryFile() would return a <type 'file'>. If this is not possible, it seems like the linux version and docs should be changed to match the windows version to align cross-platform behavior. At least, that seems to be the shared opinion of this thread from the mailing list: numpy-discussion. http://www.mail-archive.com/numpy-discussion@scipy.org/msg00271.html
To my knowledge, while platform differences in tempfile have been reported in the past, this one has not.
----------------------------------------------------------------------
Comment By: Raghuram Devarakonda (draghuram)
Date: 2007-03-28 10:43
Message:
Logged In: YES
user_id=984087
Originator: NO
I used the following code to reproduce the problem on windows XP.
----------
import array
import tempfile
testarray = array.array('B')
testarray.fromstring("\x00\x00\x00")
f = tempfile.TemporaryFile()
testarray.tofile(f)
-----------
This works fine on linux but on windows, it gives the following error:
-------------
Traceback (most recent call last):
File "c:\rags\tofile.py", line 7, in <module>
testarray.tofile(f)
TypeError: arg must be open file
-------------
Changing "f" to "f.file" seems to work, though, as explained in the
initial post. So this may be the same problem as OP reported even though I
am getting TypeError and he mentioned IOError.
I tested with 2.4 and 2.5 as I don't know how to set up python development
environment on windows (yet). I will see if I can set that up first before
working on the "fix".
Raghu.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1615275&group_id=5470
More information about the Python-bugs-list
mailing list