Customizing attribute assignment with __setattr__
Previously, we used descriptors to implement logic that was run when a specific attribute was retrieved, set, or deleted. But what if we'd like to make sure a certain block of code runs each time any attribute is set? In this exercise, you'll practice doing this with a Python magic method.
Diese Übung ist Teil des Kurses
Intermediate Object-Oriented Programming in Python
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
class BankAccount:
def __init__(self, account_number):
self.account_number = account_number
# Define a method to be executed when setting attributes
def ____(self, ____, ____):
pass