Intermediate Python3

I am doing the new Intermediate Python3 course. Currently I am working in OOP and specifically the Encapsulation topic. The class Employee involves the implementation of getter, setter and delete functions per the instructions, with the use of the Python methodology for dealing with public, protected and private access modifiers (single and double underscore). When I ran the tests to call the functions I noticed an AttributeError resulted if the get_name() function was called after the del_name() function. There are no imported files. When I examined the codecademy ‘test’ file there is a reference to using an @property decorator which isn’t mentioned in the exercise. Perhaps I am not understanding something. But I chose to handle this by adding a try/except to the get_name() function getter so all tests would pass. Is this OK or did I miss something?

If it’s the lesson I’m thinking of then I think it’s fine. I think the idea was to uncomment certain statements in turn to see how they operated (one of which showed an attribute being removed and the test was to try and access this attribute, after removal). Using try/except with a warning sent to the console or something seems like a nicer way of handling it than deliberately throwing an error.

As for @property is just much more convenient. You can skip going through specific methods every time and just use that attribute normally (it’s more like you’ve altered dunder methods for that one attribute), inst.x uses the getter method instead of immediate access and so on.

For a little more info you can see-
https://docs.python.org/3/howto/descriptor.html#properties General information about using descriptors is covered quite neatly on this page.
https://docs.python.org/3/library/functions.html#property for a brief overview of the property built-in.
If you want a little more detail perhaps- Python Descriptors: An Introduction – Real Python