Title: Getting Python variable definition called 'not defined'
Tags: python;constructor;self;python-object
Question: I am not exactly sure what this error means.
Traceback (most recent call last):
File "<stdin&gt;", line 1, in <module&gt;
File     "/Users/johndoe/Documents/CHOP_CPR_Project/CHOP_Apr07/CPRPageClass.py", line 21, in __init__
# Determine Left Side Vertical Axis
NameError: name 'size' is not defined
Relevant code for Class that I am attempting to construct:
def __init__(self, image):
# Gather initial values
self.image = image
self.size = image.size
self.pixel_array = np.asarray(self.image)
# Determine Right Side Vertical Axis
rsv_list = np.zeros(0)
for i in range(int(.2 * image.size[1]), int(.7 * image.size[1]), 5):
counter = 0
for value in self.pixel_array[i][75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0-1]:
if value != 255:
np.append(rsv_list, counter)
break
else:
counter += 1
self.rsva = image.size[0] - int(np.mean(rsv_list))
# Determine Left Side Vertical Axis
lsv_list = np.zeros(0)
for i in range(int(.2 * image.size[1]), int(.7 * image.size[1]), 5):
counter = 0
for value in self.pixel_array[i]:
if value != 255:
np.append(lsv_list, counter)
break
else:
counter += 1
self.lsva = int(np.mean(lsv_list))
It's been a while since I coded in python so I am pretty rusty. I was wondering if anybody could identify a solution to my error.
The command I tried to run in terminal that produced the error:
&gt;&gt; image = Image.open('chop_april07_Page_01.jpg')
&gt;&gt; test = CPRPageClass.CPRPage(image)
Comment: Show us the entire class definition, not just `__init__()`.  Or at least indicate where line 21 is.

Comment: It seems very odd that it's displaying the comment line `# Determine Left Side Vertical Axis` in the error traceback, as if it thinks _that_ is line 21.  Maybe it's getting confused by an old version of a `.pyc` file that never got removed?



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:07/13/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<python><constructor><self><python-object>', 'Title': "Getting Python variable definition called 'not defined'", 'ViewCount': 85, 'id': 38363265, 'user_AboutMe': None, 'user_AccountId': 6316083.0, 'user_DisplayName': 'Troll_Hunter', 'user_Reputation': 445.0, 'user_Views': 56.0, 'user_id': 4905989.0}}