numpy.fromfile OSError: first argument must be an open file (Python 3)
See original GitHub issueUsing Python 3 and Numpy 1.9.2 there is an issue with numpy.fromfile
when called on an existing file object. This code works fine in Python 2.7.
$ fh
<_io.FileIO name=8 mode='rb+'>
$ np.fromfile(fh, dtype=dtype, count=length)
OSError: first argument must be an open file
I’ve checked fh.closed
is False
, so the file is still open. The error is thrown by numpy.multiarraymodule.c#2119.
Someone mentioned these issues on Stack Overflow, but no clear solutions are present.
Any suggestions?
Issue Analytics
- State:
- Created 8 years ago
- Comments:12 (9 by maintainers)
Top Results From Across the Web
"Obtaining file position failed" while using ndarray.tofile() and ...
So my question is, how I should use the np.fromfile() and the ndarray.tofile() correctly in this case. python · python-3.x ...
Read more >numpy.fromfile — NumPy v1.24 Manual
Construct an array from data in a text or binary file. A highly efficient way of reading binary data with a known data-type,...
Read more >Reading and Writing Files in Python - DataCamp
Let's understand the first argument, i.e., file . file. file is a mandatory argument that you have to provide to the open function...
Read more >os.path — Common pathname manipulations — Python 3.11 ...
To read or write files see open(), and for accessing the filesyst... ... On Unix and Windows, return the argument with an initial...
Read more >pyfits 3.4 - PyPI
pyfits.open no longer catches OSError exceptions on missing or unreadable files– instead it raises the standard Python exceptions in such cases.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Someone pointed out to me that fromfile is designed to read straight from a file and not buffered. Using this: trace.data = np.frombuffer(fpin.read(record_dtype.itemsize * npts), record_dtype) gives me correct input so there probably is no issue. Thanks.
Randy ----- Original Message ----- From: W. Trevor King To: numpy/numpy Cc: rpratt20 Sent: Wednesday, October 07, 2015 2:35 PM Subject: Re: [numpy] numpy.fromfile OSError: first argument must be an open file (Python 3) (#6246)
Is this closable now that #6330 has landed, or should it stay open until @rpratt20’s Python 2 issue has been addressed?
— Reply to this email directly or view it on GitHub.
Thanks @charris!