There is no array attribute defined in your class, so its correct that read.array raises AttributeError.
As you have implemented
Unfortunately there are other problems too, for example self.filecontent is a binary string (without .read() method), so self.filecontent.read() would raise error. Morever self.filecontent contains entire file, therefore entire logic in __next__ seems rather questionable (and erroneous).
I am not sure what do you want to do. If you need to read entire file as single 1D numpy array, then you can do it directly (see numpy.fromfile). And if you want to read rows (there are no implicit rows in binary file...) as separate numpy arrays, then perhaps using generator expression that reads one "row" and yields appropriate numpy array would be better way (you could add caching on top of that generator expression).
As you have implemented
__next__
and __iter__
, it seems that proper way to use your class would beread = iter(ReadBinary()) # to get iterator next(read) # should return first array value ...Without calling iter first next(read) would raise error (no self.cache_index defined in __init__).
Unfortunately there are other problems too, for example self.filecontent is a binary string (without .read() method), so self.filecontent.read() would raise error. Morever self.filecontent contains entire file, therefore entire logic in __next__ seems rather questionable (and erroneous).
I am not sure what do you want to do. If you need to read entire file as single 1D numpy array, then you can do it directly (see numpy.fromfile). And if you want to read rows (there are no implicit rows in binary file...) as separate numpy arrays, then perhaps using generator expression that reads one "row" and yields appropriate numpy array would be better way (you could add caching on top of that generator expression).