Jun-21-2017, 10:49 PM
I need help figuring out how to read in a binary file, and then placing it into a numpy array.
The error I am getting is: AttributeError: 'ReadBinary' object has no attribute 'array'
Thank you in advance.
The error I am getting is: AttributeError: 'ReadBinary' object has no attribute 'array'
Thank you in advance.
import numpy as np
import collections
class ReadBinary(collections.Mapping):
'''
Reads in Binary Code.
'''
filename = 'R033P010BDAS.eud'
def __init__(self):
self.cache= []
with open(self.filename, 'rb') as self.file:
self.filecontent = self.file.read()
def __len__(self):
return len(self.filecontent)
def __iter__(self):
self.cache_index = 0
return self
def __next__(self):
self.cache_index += 1
if len(self.filecontent) >= self.cache_index:
return self.cache[self.cache_index-1]
if self.file.closed:
raise StopIteration
row= self.filecontent.read()
if not row:
self.file.close()
raise StopIteration
array = np.fromstring(self.filecontent)
self.cache.append(array)
return array
def __getitem__():
pass
read = ReadBinary()
print(read.array)
