Oct-11-2018, 03:02 AM
Hello.
I am having trouble understanding arrays and how to populate them(later). I am just starting out. Right now I get an error message for the code below, yet I copied the program (below) from the book and the classArray (below) is copied from our instructor. I'm trying to learn arrays by trying the most basic code from my book. It is frustrating to get this error. Here is what I have:
I am having trouble understanding arrays and how to populate them(later). I am just starting out. Right now I get an error message for the code below, yet I copied the program (below) from the book and the classArray (below) is copied from our instructor. I'm trying to learn arrays by trying the most basic code from my book. It is frustrating to get this error. Here is what I have:
from classArray import Array a = Array(8) for i in range(len(a)): a[i] = i + 1 for item in a: print(item)Here is the class Array (classArray.py)
class Array(object): def __init__(self, capacity, fillValue = None): """Capacity is the static size of the array. fillValue is placed at each position.""" self._items = list() for count in range(capacity): self._items.append(fillValue) def __len__(self): """-> The capacity of the array.""" return len(self._items) def __str__(self): """-> The string representation of the array.""" return str(self._items) def __iter__(self): """Supports iteration over a view of an array.""" return iter(self._items) def __getitem__(self, index): """Subscript operator for access at index.""" return self._items[index] def __setitem__(self, index, newItem): """Subscript operator for replacement at index.""" self._items[index] = newItemAnd here is the error message I get:
for i in range(len(a)): TypeError: 'Array' object is not callable