I want to get all the attributes of an object in Python I have defined myself to create a string representation. I want to prevent writing it by hand and filling in all the variables myself, so adding/removing attributes in the future does not amount to mistakes.
For example, in the code below I am looking for a way to retrieve all the attributes I have defined myself: email, password and birthday.
Is there a way to do this in Python?
class Account:
def __init__(self, email, password, birthday):
self.email = email
self.password = password
self.birthday = birthday
def __str__(self):
delim = ","
# I want to prevent writing this all out
return f"{self.email}{delim}{self.password}{delim}{self.birthday}"
print(Account("manfred@gmail.com", "hunter2", 3))