Classes

Classes are a core part of a computer programming philosophy known as Object Orientated Programming. I am not going to dig into that now! In fact, I’m not going to explain it at all, I’m simply going to provide a demo that shows how it works in Python if you happen to need it. The intended audience of this handbook is unlikely to need it, and if you do, I’ll happily sit with you to help you get it working. The above is a long way of saying you should probably skip this section.

#### File: person.py

class Person():

    def __init__(self, given_name, family_name, email=None):
        self.given_name = given_name
        self.family_name = family_name
        if email:
            self.email = email
            self.email_provided = True
        else:
            self.email_provided = False

    def set_email(self, email):
        self.email = email
        self.email_provided = True

    def get_name(self):
        return(self.given_name+" "+self.family_name)

    def get_email(self):
        if self.email_provided:
            return self.email
        else:
            return ""
#### File: main.py
import person

me = person.Person("Paul", "Baumgarten", "pbaumgarten@isl.ch")

print("Your email is: " + me.get_email())
print("Your full name is: " + me.get_name())

Note: Naming conventions in Python: