In this simple case you can use vars():

an = Animal()
attrs = vars(an)
# {'kids': 0, 'name': 'Dog', 'color': 'Spotted', 'age': 10, 'legs': 2, 'smell': 'Alot'}
# now dump this in some way or another
print(', '.join("%s: %s" % item for item in attrs.items()))

If you want to store Python objects on the disk you should look at shelve — Python object persistence.

Answer from Jochen Ritzel on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-get-a-list-of-class-attributes-in-python
How to Get a List of Class Attributes in Python? - GeeksforGeeks
July 12, 2025 - Number has three class attributes and one instance attribute set in __init__. The show() method prints all attributes. Creating n with attr=2 and calling n.show() displays them while vars(n) shows only the instance attributes.
Discussions

python - Is there a built-in function to print all the current properties and values of an object? - Stack Overflow
Some classes/objects don't contain any __dict__ attribute/member. I know it's crazy, but true. Built-ins like int and str or re.MatchObjects are common examples. Try 'hello'.__dict__, then try dir('hello') 2012-03-18T04:50:28.433Z+00:00 ... Well, this answer at least prints both attributes' names and values... More on stackoverflow.com
🌐 stackoverflow.com
python - List attributes of an object - Stack Overflow
The issue of dict usage just showed up on r/python. someone pointed out that vars(a) is equivalent to a.__dict__ 2013-01-12T05:15:08.957Z+00:00 ... To be specific, pprint.pprint(a.__dict__) does a pretty-print on the attributes. 2016-08-27T00:00:26.427Z+00:00 ... Note that this only works for user-defined classes, not for built-in or extension types. 2017-10-22T07:48:40.807Z+00:00 ... this won't work if the class has a __slots__ instead of a __dict__, and ... More on stackoverflow.com
🌐 stackoverflow.com
April 20, 2010
Print Object Attributes in Python - Ask a Question - TestMu AI Community
Is there a built-in function to print object attributes in Python and display all the current properties and values of an object? I’m looking for something similar to PHP’s print_r function, so I can easily debug my scripts by examining the state of the object in question. More on community.testmuai.com
🌐 community.testmuai.com
0
December 19, 2024
print class attributes from a list?
Python doesn't know how to turn your Car object into a string. To teach it to do that, you need to implement a __str__ method (and maybe a __repr__ method) in your class. See more info here More on reddit.com
🌐 r/learnpython
3
1
April 16, 2022
🌐
w3resource
w3resource.com › python-exercises › class-exercises › python-class-basic-1-exercise-12.php
Python: Print all the attributes and their values of instances - w3resource
class Student: school = 'Forward Thinking' address = '2626/Z Overlook Drive, COLUMBUS' student1 = Student() student2 = Student() student1.student_id = "V12" student1.student_name = "Ernesto Mendez" student2.student_id = "V12" student2.marks_language = 85 student2.marks_science = 93 student2.marks_math = 95 students = [student1, student2] for student in students: print('\n') for attr in student.__dict__: print(f'{attr} -> {getattr(student, attr)}') ... student_id -> V12 student_name -> Ernesto Mendez student_id -> V12 marks_language -> 85 marks_science -> 93 marks_math -> 95 ... Write a Python program to define a Student class, create two instances with different attribute values, and print each instance's __dict__.
🌐
Flexiple
flexiple.com › python › print-object-attributes-python
How to Print Object Attributes in Python? - Flexiple
March 22, 2024 - When called on an object, it returns a list of names (as strings) of all the attributes and methods associated with that object. This includes both the built-in attributes of a Python object and those defined in a class. Here's a simple example. class ExampleClass: def __init__(self, value): self.value = value def display(self): print("Displaying value:", self.value) example_object = ExampleClass(42) # Using dir() to print all attributes and methods of example_object print("Attributes and methods of example_object:", dir(example_object))
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › print object properties and values in python?
Print Object Properties and Values in Python? - Spark By {Examples}
May 31, 2024 - # Using vars() and pprint() functions from pprint import pprint # Class for demonstration class MyClass: def __init__(self): self.prop1 = "value1" self.prop2 = "value2" # Create object obj = MyClass() # Call the vars() on Object obj_vars = vars(obj) # Print the properties pprint(obj_vars) This example yields the below output. # Output: {'prop1': 'value1', 'prop2': 'value2'} We will use the above generic class (MyClass) for all our examples. Alternatively, you can also use the dir() method...
Find elsewhere
🌐
datagy
datagy.io › home › python posts › python: print an object’s attributes
Python: Print an Object's Attributes • datagy
December 20, 2022 - Learn how to print all of a Python object's attributes using the dir() and vars() functions, and how to print pretty using the pprint module.
🌐
Learning About Electronics
learningaboutelectronics.com › Articles › How-to-display-all-attributes-of-a-class-or-instance-of-a-class-in-Python.php
How to Display All Attributes of a Class or an Instance of a Class in Python
We then can print out all of the attributes of this Car1 class to see what attributes it contains and what values these variables are assigned it using the __dict__ method.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-print-object-attributes-in-python
How to Print Object Attributes in Python - GeeksforGeeks
July 23, 2025 - There are several ways to print the attributes of an object. Let's explore them: The vars() function returns the __dict__ attribute of an object, which is a dictionary containing the object’s writable attributes.
🌐
FavTutor
favtutor.com › blogs › print-object-attributes-python
How to Print Object Attributes in Python? (with Code)
October 14, 2022 - ... Passing any parameter to the vars() function is optional. It can also be called without passing any parameter to it. Let's take a few examples to understand the different cases: ... # listing out all attributes of an object in Python # import pprint module from pprint import pprint # create a class class Student: # class variable var = 1 def __init__(self, name, age, id): self.name = name self.age = age self.id = id # creating object s = Student("Alice", 14, 23) # calling the vars() function ...
🌐
Python Forum
python-forum.io › thread-13408.html
Classes: How to Print Specific Attributes
Hello. I'm having trouble printing specific attributes from my object-array. My code is below, and it contains my class Student, class Array, along with two function (main, and the function that creates the array. I'm trying to print the first and l...
🌐
Delft Stack
delftstack.com › home › howto › python › python print object attributes
How to Print Object's Attributes in Python | Delft Stack
February 12, 2024 - In the second method, the getattr() function dynamically fetches the attribute specified by attribute_name and prints its value. getattr() is a built-in Python function that is used to get the value of an attribute of an object.
🌐
W3docs
w3docs.com › python
Is there a built-in function to print all the current properties and values of an object?
In Python, you can use the built-in function vars() to print the properties and values of an object. vars() returns the __dict__ attribute of an object, which is a dictionary containing the object's attributes and their values.
🌐
Syntx Scenarios
syntaxscenarios.com › home › python › how to print all attributes of an object in python?
How to Print All Attributes of an Object in Python?
March 1, 2025 - However, before printing object attributes, its better to check if an object has attributes. vars(object) returns a dictionary of all attributes and their current values. It’s like looking inside the object’s “storage”: class Book: def ...
🌐
Mouse Vs Python
blog.pythonlibrary.org › home › how to get a list of class attributes in python
How to Get a List of Class Attributes in Python - Mouse Vs Python
January 31, 2020 - It’s quite powerful and can tell you lots of wonderful things about your class or one you didn’t even write. Anyway, the next easiest way that I found was to use Python’s callable builtin: variables = [i for i in dir(t) if not callable(i)] You can read more about callable in the Python docs. Basically all that callable does is return a True or False depending on whether or not the object you passed it is callable.
🌐
EnableGeek
enablegeek.com › home › how to print all properties of object in python
How to Print All Properties of Object in Python - EnableGeek
March 19, 2024 - This ensures that all instances of the class have the same set of instance variables, which can make your code easier to understand and maintain. To add a value to an attribute of a Python object, you can simply assign a new value to the attribute. Here is an example: ... class MyClass: def __init__(self, x): self.x = x my_object = MyClass(1) print("Value of x before adding: ", my_object.x) my_object.x = 2 print("Value of x after adding: ", my_object.x)
🌐
TestMu AI Community
community.testmuai.com › ask a question
Print Object Attributes in Python - Ask a Question - TestMu AI Community
December 19, 2024 - Is there a built-in function to print object attributes in Python and display all the current properties and values of an object? I’m looking for something similar to PHP’s print_r function, so I can easily debug my scri…
🌐
Reddit
reddit.com › r/learnpython › print class attributes from a list?
r/learnpython on Reddit: print class attributes from a list?
April 16, 2022 -

I've got a class Car, I have instances of car in the main body of the code, I've added the car instances to a list and now want to print specific elements of that list, but it just print's "<__main__.Car object at 0x00000297B91FF040>" or "None" I need it to print

("AT11CAR", "Audi", "R8", "Black", "1000", "500", "Dundee", "3")

without the brackets etc. If someone chooses Audi, it print's the first two cars from the lists' information (the line above). I have multiple car makes in this list so I don't really want to do for car in car print(car) or know away around it. Anything will help, thanks.

Here's a snippet: https://pastebin.com/QCgkY69E

any help is appreciated thank you.