ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> numpy-discussion
numpy-discussion
Re: [Numpy-discussion] fromfile and tofile access with a tempfile.TemporaryFile()
by Tim Hirzel other posts by this author
Dec 13 2006 1:28PM messages near this date
Re: [Numpy-discussion] fromfile and tofile access with a tempfile.TemporaryFile() | Re: [Numpy-discussion] fromfile and tofile access with a tempfile.TemporaryFile()
Thanks for everyone's help and thoughts.  I agree that this behavior is 
buggy.  I submitted a bug report to the python project at sourceforge, 
with a link to this thread.  Hopefully the report will be helpful.

tim

Charles R Harris wrote:
> 
> 
>  On 12/12/06, *Travis Oliphant* <oliphant@[...].edu 
>  <mailto:oliphant@[...].edu>> wrote:
> 
>      Tim Hirzel wrote:
> 
>      >Good thought Chris,
>      >Normal reading and writing does seem to work. ..
>      >But, my friend Daniel figured out a workaround when I asked to
>      confirm
>      >this behavior on his windows setup (and it is does behave the
>      same for
>      >him).  The first clue was this:
>      >
>      > >>> f = tempfile.TemporaryFile()
>      > >>> type(f)
>      ><type 'instance'>
>      > >>> g = open("temp","w+b")
>      > >>> type(g)
>      ><type 'file'>
>      >
>      >so Daniel did a dir(f) and found the 'file' attribute
>      >
>      >so if you do (where 'a' is a numpy array)
>      > >>> a.tofile(f.file)
>      >It works!
>      >
>      >writing to the "file" attribute of the TemporaryFile, it works
>      fine!  So
>      >that's good, but still a little hinky.  Especially since it works on
>      >linux...
>      >on a linux platform, what does type( tempfile.TemporaryFile())
>      return?  I
>      >assume an <type 'instance'>  as well...
>      >
>      >anways, so at least there is a quick repair for now.  Good news is, I
>      >assume using 'f.file' would work on linux too in terms of having a
>      >single cross-platform solution.
>      >
>      >
>      There is no file attribute on Linux.   On linux you get
> 
>      >>> type(f)
>      <type 'file'>
> 
>      So, you might have to do something like:
> 
>      if not isinstance(f, file):
>         f = f.file
> 
>      before passing f to the tofile method.
> 
>      It seems to me that the temporary file mechanism on Windows is a
>      little
>      odd.
> 
> 
>  Looks like a tempfile bug to me. Python should be cross platform and 
>  since the file attribute is correctly set on windows, I don't see why 
>  the tempfile can't be made to behave correctly.
> 
>  Chuck
> 
> 
>  ------------------------------------------------------------------------
> 
>  _______________________________________________
>  Numpy-discussion mailing list
>  Numpy-discussion@[...].org
>  http://projects.scipy.org/mailman/listinfo/numpy-discussion
>    
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@[...].org
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Thread:
Tim Hirzel
Charles R Harris
Tim Hirzel
Charles R Harris
Tim Hirzel
Christopher Barker
Tim Hirzel
Travis Oliphant
Charles R Harris
Tim Hirzel
Lisandro Dalcin

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved