admin管理员组文章数量:1406444
I am attempting to load .bin files into Python as a uint8 then do stuff to them then load in the next file:
for filepath in bin_files:
data = np.fromfile(filepath,dtype=np.uint8)
bin_files
is my list of files that all look fine. np
is the numpy library that I load in upon running the script. The error I get is in np.fromfile
. When I run the script the error generated is:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
File c:\users\jlake\onedrive - cidra\desktop\python\sonaralgo\decryptbinfiles.py:24
21 bin_files.append(os.path.join(root, file))
23 for filepath in bin_files:
---> 24 data = np.fromfile(filepath,dtype=np.uint8)
25 S = len(data)
26 match S:
KeyError: '__builtins__'
The weird part is after the error if I highlight the np.fromfile
line and hit F9 the line runs fine and I get my data loaded.
I tried all different things over several days. Currently I just bypass the error by running things using F9. I am using Spyder as an IDE and F9 runs the line or lines of coded highlighted at the time.
The files were generated using our legacy product (not Python). The weird part is if I execute that line using F9 (in Spyder) it runs fine. I only get that error when I hit "run file", or "debug file" in Spyder.
This doesn't actually fix the problem but is a work around: I replaced
data = np.fromfile(filepath,dtype=np.uint8)
with:
with open(filepath, 'rb') as file:
data = array.array('B',file.read())
data = np.array(data)
Now I can run the script without without error and without using F9.
本文标签: Python Numpy Builtins IssueStack Overflow
版权声明:本文标题:Python Numpy Builtins Issue - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745015763a2637829.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论