I am writing an email parser and cannot decide how much logic should be included in the
__init__ function. I know that a constructor should make the object ready for use, but are there best practices?
I've added several statements to my constructor:
def __init__(self, message): assert isinstance(message, basestring) parsed_message = email.message_from_string(message) if self._is_email(parsed_message): self.email_obj = parsed_message email_payload = parsed_message.get_payload() self.valid_urls = self._find_valid_urls(email_payload) # ... some other stuff like looking for keywords etc.
What do you consider the most pythonic way:
- Should I create a simple email object which possesses several methods that extract and return keywords, included URLs etc?
- Do you consider it better to process all this information in the
__init__method and putting all results in object variables?