Skip to content

Commit 8180928

Browse files
committed
change 'max_size()' to '__len__'
1 parent 5666a1b commit 8180928

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

adafruit_fram.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,6 @@ def __init__(self, max_size, write_protect=False, wp_pin=None):
7575
else:
7676
self._wp_pin = wp_pin
7777

78-
@property
79-
def max_size(self):
80-
""" The maximum size of the current FRAM chip. This is the highest
81-
register location that can be read or written to.
82-
"""
83-
return self._max_size
84-
8578
@property
8679
def write_wraparound(self):
8780
""" Determines if sequential writes will wrapaound the ``FRAM.max_size``
@@ -116,6 +109,23 @@ def write_protected(self, value):
116109
if not self._wp_pin is None:
117110
self._wp_pin.value = value
118111

112+
def __len__(self):
113+
""" The maximum size of the current FRAM chip. This is the highest
114+
register location that can be read or written to.
115+
116+
.. code-block:: python
117+
118+
fram = adafruit_fram.FRAM()
119+
120+
# maximum size returned by len()
121+
len(fram)
122+
123+
# can be used with range
124+
for i in range(0, len(fram))
125+
"""
126+
return self._max_size
127+
128+
119129
def __getitem__(self, key):
120130
""" Read the value at the given index, or values in a slice.
121131

docs/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
77
.. automodule:: adafruit_fram
88
:members:
9-
:special-members: __getitem__, __setitem__
9+
:special-members: __len__, __getitem__, __setitem__

0 commit comments

Comments
 (0)