1. Learn
  2. /
  3. Courses
  4. /
  5. Intermediate Object-Oriented Programming in Python

Connected

Exercise

Accessing attributes that don't exist

Sometimes, you may try to access an attribute that does not exist in the namespace for an object. When this happens, typically, an AttributeError is thrown. In this exercise, you'll practice handling this scenario using one of Python's magic methods. Enjoy!

Instructions

100 XP
  • Define a method to be executed when referencing an attribute not defined in the BankAccount namespace; this method should take parameters self and name.
  • Add logic to the magic method to print a message suggesting the attribute referenced should be set for the object.
  • Create an object of the BankAccount class, and attempt to access the routing_number attribute; observe the output.