I've defined a new class called Email, and had to create a few methods. The problem is, I define the variables in the constructor, and the code analysis on Spyder keeps saying that inbox
, is_spam
and has_been_read
aren't defined in some of my methods, even though I defined it in the constructor.
I have searched everywhere, but I really can't figure out what I am doing wrong?
I am using Spyder 4.1.5 and Python 3.8
My code is as below:
class Email(object):
def __init__(self, has_been_read, email_contents, is_spam, from_address, inbox):
assert type(has_been_read) == bool and type(is_spam) == bool
self.has_been_read = has_been_read
self.email_contents = email_contents
self.is_spam = is_spam
self.from_address = from_address
self.__inbox = []
def mark_as_read(self):
# Creating method to change has_been_read boolean to True
return self.has_been_read == True
def mark_as_spam(self):
# Creating method to change is_spam to True
return self.is_spam == True
def add_email(self, eamil_contents, from_address):
return Email(False, email_contents, False, from_address)
inbox.append(Email)
def get_count(self):
print(len.inbox)
def get_email(self, i):
print(inbox[i].email_contents)
return inbox[i].mark_as_read
def get_unread_emails(self):
for i in inbox:
if has_been_read == False:
print(i)
def get_spam_emails(self):
for i in inbox:
if is_spam == True:
print(i)
def delete(self, i):
del self.inbox[i]