>>> class new_class():
...   def __init__(self, number):
...     self.multi = int(number) * 2
...     self.str = str(number)
... 
>>> a = new_class(2)
>>> a.__dict__
{'multi': 4, 'str': '2'}
>>> a.__dict__.keys()
dict_keys(['multi', 'str'])

You may also find pprint helpful.

Answer from Roger Pate on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › any way to get all attributes of an object in python?
r/learnpython on Reddit: Any way to get ALL attributes of an object in python?
June 20, 2024 -

I'm using the plex python library to get some info from my plex server.

What I wanted to get was the path of a movie.

I tried to use dir(movie_object), vars(movie_object), and movie_object.__dict__ to try and find all of the movie attributes, and to see where the path was stored.

But there was no attribute that contained the file path information.

In the end I found it under movie_object.location by inspecting the object in the VSCode debugging tools.

Why does VSCode show the location attribute, but dir, vars, or __dict__ do not show it?

Is there a way to reliably get ALL of an objects attributes in python?

Discussions

introspection - Get all object attributes in Python? - Stack Overflow
Is there a way to get all attributes/methods/fields/etc. of an object in Python? vars() is close to what I want, but it doesn't work unless an object has a __dict__, which isn't always true (e.g. ... More on stackoverflow.com
🌐 stackoverflow.com
python - Get an object attribute - Stack Overflow
How to access (get or set) object attribute given string corresponding to name of that attribute (3 answers) Closed 7 years ago. Simple question but since I'm new to python, comming over from php, I get a few errors on it. More on stackoverflow.com
🌐 stackoverflow.com
Accessing attributes of a class
How do I access the attributes of a class, such as, __bases__, __name__, __qualname__? When I do this, class C: pass dir(C) then it gives me, ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', ... More on discuss.python.org
🌐 discuss.python.org
10
0
February 22, 2022
python - How to access (get or set) object attribute given string corresponding to name of that attribute - Stack Overflow
How do you set/get the values of attributes of t given by x? class Test: def __init__(self): self.attr1 = 1 self.attr2 = 2 t = Test() x = "attr1" Note that the same tech... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Bobby Hadz
bobbyhadz.com › blog › python-get-attribute-of-object-by-name
Access object attribute by String Name in Python | bobbyhadz
Use the `getattr()` function to get an object attribute by name. The `getattr` function returns the value of the provided attribute of the object.
🌐
Vultr Docs
docs.vultr.com › python › built-in › getattr
Python getattr() - Retrieve Attribute Value | Vultr Docs
September 27, 2024 - The getattr() function in Python provides a dynamic way of accessing the attributes of an object. This built-in function retrieves the value of a named attribute from an object, allowing for flexible code implementations where attributes might ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-getattr
Python getattr() | DigitalOcean
August 3, 2022 - Using default value : Cgpa of the student is = 3.0 Attribute is not found :( Notice that AttributeError is raised when the default value is not provided while calling getattr() function. The main reason to use python getattr() is that we can get the value by using the name of the attribute ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-getattr-method
Python | getattr() method - GeeksforGeeks
July 11, 2025 - The getattr() method in Python returns the value of a named attribute of an object. If the attribute is not found then it returns the default value provided.
Find elsewhere
🌐
pythoncodelab
pythoncodelab.com › home › get attributes of object python
Get attributes of object Python - pythoncodelab
November 2, 2025 - The dir() function lists all attributes which includes special (dunder) methods like __init__ and user defined attributes like name, age in our above example. If I summarized for “how to get all attributes of an object Python”, dir() would ...
🌐
Stack Abuse
stackabuse.com › bytes › get-all-object-attributes-in-python
Get All Object Attributes in Python
August 24, 2023 - Python provides a built-in function, dir(), which returns a list of all attributes and methods of an object, which also includes those inherited from its class or parent classes. Consider a simple class, Company, with a few attributes: class Company: def __init__(self, name, industry, num_employees): self.name = name self.industry = industry self.num_employees = num_employees
🌐
Python Central
pythoncentral.io › how-to-get-an-attribute-from-an-object-in-python
How to get an attribute from an object in Python - Python Central
December 29, 2021 - In Python, besides the normal dot-style attribute access, there's a built-in function, getattr, which is also very useful for accessing an attribute. The built-in function getattr(object, name[, default]) returns the value of a named attribute of object, where name must be a string.
🌐
Bobby Hadz
bobbyhadz.com › blog › python-get-attributes-of-object
Get all Attributes or Methods of an Object in Python | bobbyhadz
April 10, 2024 - The dir() function takes an object and returns a list containing the object's attributes. If you pass a class to the function, it returns a list of the names of the class's attributes, and recursively of the attribute of its base classes.
🌐
Finxter
blog.finxter.com › how-to-access-an-object-attribute-given-the-attribute-name-as-a-string
How to Access an Object Attribute Given the Attribute Name as a String? – Be on the Right Side of Change
But you cannot use the syntax object."attribute" because the dot notation only allows for name-access like this: object.attribute. How do you resolve this problem? This article will show you how! Quick Solution: There are four ways to access the object attribute in Python via the built-in functions: getattr() — provides access to the object attribute,
🌐
Python.org
discuss.python.org › python help
Accessing attributes of a class - Python Help - Discussions on Python.org
February 22, 2022 - How do I access the attributes of a class, such as, __bases__, __name__, __qualname__? When I do this, class C: pass dir(C) then it gives me, ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__'] h...
🌐
datagy
datagy.io › home › python posts › python: print an object’s attributes
Python: Print an Object's Attributes • datagy
December 20, 2022 - Based on the class definition above, we know that the object has some instance attributes – specifically, name, age, and puppies. We can access an object’s instance attribute by suffixing the name of the attribute to the object.
🌐
FavTutor
favtutor.com › blogs › print-object-attributes-python
How to Print Object Attributes in Python? (with Code)
October 14, 2022 - To print all the attributes of an object in Python, you can use the 'getmembers()' function of the inspect module. This function returns the list of tuples containing the attributes along with their values.
🌐
LabEx
labex.io › questions › how-to-access-object-attributes-71
How to Access Object Attributes in Python | LabEx
July 25, 2024 - For example, if you have an object ... --> C[Attribute 2] A --> D[Method 1()] A --> E[Method 2()] Python also provides the getattr() function, which allows you to dynamically access an object's attributes....
🌐
Flexiple
flexiple.com › python › print-object-attributes-python
How to Print Object Attributes in Python? - Flexiple
The inspect.getmembers(obj) function retrieves all the members of obj. The loop then filters out unique methods (those starting with __) and prints the name and value of each attribute.
🌐
Stack Exchange
blender.stackexchange.com › questions › 259292 › access-attributes-of-objects-by-string
python - Access attributes of objects by string - Blender Stack Exchange
April 1, 2022 - + my_attribute) assuming ob was defined as your object. $\endgroup$ ... $\begingroup$ Thanks you both, getattr works perfectly in that situation, eval would require ob to be in the local scope, but I'll keep it in mind $\endgroup$ ... $\begingroup$ + it's really not safe to use eval on user input strings. It can execute malicious code easily. Try with attribute's name name, quit() and see what happens $\endgroup$ ... Find the answer to your question by asking.