Junior
How to get a list of attributes of an object in Python?
sobes.tech AI
Answer from AI
Using built-in functions.
# Getting a list of all attributes and methods (including special ones)
print(dir(object))
# Getting a dictionary of an object's attributes (excluding most special ones)
print(object.__dict__)
# Using getattr to get the value of a specific attribute or a default value
print(getattr(object, 'attribute_name', default_value))
You can also iterate over __dict__ or dir and filter by type (for example, using callable() for methods).