>>> 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
🌐
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 - Another way of finding a list of attributes is by using the module inspect. This module provides a method called getmembers() that returns a list of class attributes and methods.
Discussions

Setting list as a class attribute
An attribute, like a variable, is simply holding a reference to a Python object, not the object itself. The object referenced can be any Python object including a new empty list object, which is what [] creates. Thus, when you have self.cars = [] in an instance method of a class, when the instance is created and the corresponding method is run (by default in the case of __init__) either a new attribute will be created for the instance referenced by self and assigned to reference a new list object, or the reference in an existing attribute will be replaced by a reference to the new list object (this would be in a different method from __init__). EDIT: Sorry, keyboard problems, kept submitting before I pressed finished. More on reddit.com
🌐 r/learnpython
4
3
March 11, 2024
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
0
0
February 22, 2022
python - Getting attributes of a class - Stack Overflow
It works dandy both in Python 2.7 and Python 3.x. If you want a list of these items, you will still need to use inspect. ... Is that answer too simple and too correct to deserve any points, and should even deserve bad points? It seems that economy and simplicity no longer pay off nowadays. 2020-05-01T07:32:27.493Z+00:00 ... He wants to list attributes... More on stackoverflow.com
🌐 stackoverflow.com
How to access attributes of a class in a list that was made my iteration?
page_list[0].image would refer to whatever image is referencing in the 1st Page instance in the list. (I'm going with all lowercase here, as your post appears to have mixed cases which you probably didn't intend. Class would usually start with an uppercase, and variables/attributes are usually all lowercase.) PS. Code should perhaps be something like below: class Page: def __init__(self, image, other_stuff) self.image = image self.other_stuff = other def pdfloader(): pages = convert_from_bytes(path) for page in pages: page_list.append(Page(image = page, other_stuff = None)) page_list = [] somepath = Path.cwd() / 'somefolder' pdfloader(somepath) # iterate through list as required for page in page_list: process(page) # page would reference an instance of Page More on reddit.com
🌐 r/learnpython
1
1
July 24, 2023
People also ask

What happens if both instance attribute and class attribute are defined?

In that case, the instance namespace takes precedence over the class namespace. If there is an attribute with the same name in both, the instance namespace will be checked first and its value returned.

🌐
toptal.com
toptal.com › python › python-class-attributes-an-overly-thorough-guide
Python Class Attributes: An Overly Thorough Guide | Toptal®
What is a Python namespace?

A Python namespace is a mapping from names to objects, with the property that there is zero relation between names in different namespaces. Namespaces are usually implemented as Python dictionaries, although this is abstracted away.

🌐
toptal.com
toptal.com › python › python-class-attributes-an-overly-thorough-guide
Python Class Attributes: An Overly Thorough Guide | Toptal®
Python class method versus instance method: What’s the difference?

In Python, a class method is a method that is invoked with the class as the context. This is often called a static method in other programming languages. An instance method, on the other hand, is invoked with an instance as the context.

🌐
toptal.com
toptal.com › python › python-class-attributes-an-overly-thorough-guide
Python Class Attributes: An Overly Thorough Guide | Toptal®
🌐
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 - The first method that we will look at is using Python’s inspect module. import inspect variables = [i for i in dir(t) if not inspect.ismethod(i)] Doesn’t look too complicated, does it? But it requires an import and I’d prefer not to do that. On the other hand, if you need to do introspection, the inspect module is a great way to go. It’s quite powerful and can tell you lots of wonderful things about your class or one you didn’t even write.
🌐
Reddit
reddit.com › r/learnpython › setting list as a class attribute
r/learnpython on Reddit: Setting list as a class attribute
March 11, 2024 -

Hi!

I just finished a turtle crossing ( a.k.a. Frogger) game as part of an online bootcamp. It uses the turtle library.

I managed quite easily, but there is one point which I can't really wrap my head around.

So I am generating Car class objects in random lanes. In order to be able to move them, query them in loops, etc. One of the init attributes is

self.cars = [ ]

Hence adding them to a list where I can apply different methods on them.

I remembered this from a previous lesson (snake game) but I still don't fully understand how an attribute can be a list.

Can someone explain this to a beginner?

🌐
Tutorialspoint
tutorialspoint.com › python › python_class_attributes.htm
Python - Class Attributes
__bases__ − A possibly empty tuple containing the base classes, in the order of their occurrence in the base class list. To access built-in class attributes in Python, we use the class name followed by a dot (.) and then attribute name.
🌐
Toptal
toptal.com › python › python-class-attributes-an-overly-thorough-guide
Python Class Attributes: An Overly Thorough Guide | Toptal®
January 16, 2026 - Python class attributes can lead to elegant code—as well as bugs. This guide outlines use cases for attributes, properties, variables, objects, and more.
Find elsewhere
🌐
Python Tutorial
pythontutorial.net › home › python oop › python class attributes
Understanding Python Class Attributes By Practical Examples
November 13, 2020 - When you access an attribute via an instance of the class, Python searches for the attribute in the instance attribute list. If the instance attribute list doesn’t have that attribute, Python continues looking up the attribute in the class attribute list.
🌐
Python.org
discuss.python.org › python help
Accessing attributes of a class - Python Help - Discussions on Python.org
February 22, 2022 - 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__', ...
🌐
Python documentation
docs.python.org › 3 › tutorial › classes.html
9. Classes — Python 3.14.3 documentation
Attribute references use the standard syntax used for all attribute references in Python: obj.name. Valid attribute names are all the names that were in the class’s namespace when the class object was created.
🌐
Built In
builtin.com › software-engineering-perspectives › python-attributes
Python Attributes: Class vs. Instance | Built In
Summary: Python class attributes are shared across all instances, while instance attributes are unique to each object. Attribute lookup starts in the instance’s namespace, then checks the class. Reassigning a class attribute from an instance creates a new instance attribute that shadows the original.
🌐
GeeksforGeeks
geeksforgeeks.org › class-instance-attributes-python
Class and Instance Attributes in Python - GeeksforGeeks
2. dir() - This function displays more attributes than vars function,as it is not limited to instance. It displays the class attributes as well. It also displays the attributes of its ancestor classes.
Published   September 5, 2024
🌐
Turing
turing.com › kb › introduction-to-python-class-attributes
A Guide to Python Class Attributes and Class Methods
Python's classes and objects allow you to design your code in a way that is intuitive and easy to understand. This article will take you through Python class attributes, their purpose and how they’re used as well as class methods and how to create them.
🌐
W3Schools
w3schools.com › python › python_class_properties.asp
Python Class Properties
Remove List Duplicates Reverse a String Add Two Numbers · Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... Properties are variables that belong to a class.
🌐
Quora
quora.com › What-is-the-best-way-to-list-only-the-class-attributes-of-a-class-in-Python
What is the best way to list only the class attributes of a class in Python? - Quora
Answer (1 of 3): You can use vars(), which will return a dictionary with the class attributes. [code] class MyClass( ): def __init__(self): self.foo = 9 self.bar = 10 def class_attrs(self): return vars(self) c = MyClass() c.class_attrs() # ==> {'foo': 9, 'bar': 10} [/code] ED...
🌐
Tutorial Teacher
tutorialsteacher.com › articles › class-attributes-vs-instance-attributes-in-python
Class attributes vs instance attributes in Python
Instance attributes are attributes or properties attached to an instance of a class. Instance attributes are defined in the constructor. The following table lists the difference between class attribute and instance attribute:
🌐
Iditect
iditect.com › programming › python-example › how-to-get-a-list-of-class-attributes-in-python.html
How to Get a List of Class Attributes in Python?
To get a list of class attributes in Python, you can use the built-in dir() function, the vars() function, or the __dict__ attribute of the class object.
🌐
freeCodeCamp
freecodecamp.org › news › python-attributes-class-and-instance-attribute-examples
Python Attributes – Class and Instance Attribute Examples
April 12, 2022 - When creating a class in Python, you'll usually create attributes that may be shared across every object of a class or attributes that will be unique to each object of the class. In this article, we'll see the difference between class attributes and ...
🌐
W3docs
w3docs.com › python
List attributes of an object
['__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__', 'x', 'y'] ... Note that dir() also returns the built-in attributes of the object, in addition to the attributes that you defined in the class.
🌐
Reddit
reddit.com › r/learnpython › how to access attributes of a class in a list that was made my iteration?
r/learnpython on Reddit: How to access attributes of a class in a list that was made my iteration?
July 24, 2023 -

I've had a lot of issues getting information into and out of a list of classes that I've generated by iteration. In my latest project, I'm using PDF2image to open a pdf and store each page in a list of classes as well as a few other attributes unique to each page. My problem is that I have a really loose grip on how to handle data coming in and out of functions and particularly classes. Like in the following:

'class page():

 def __init__(self, image, other_stuff)

      Self. Image = image

      Self. Other_stuff = other

Page_list = []

def pdfloader():

 Pages = convert_from_bytes(path)

 For page in pages:

      Page_list.append(page(image = page, other_stuff = None))

'

So like, in this example, I've appended 'page_list' with a new instance for each page that was pulled from the pdf and stored as an array. This works great. But now I have no idea how to access each instance to get the array, and then write 'other_stuff' to that instance.

(Also, sorry for the formatting, I'm writing this on mobile and I have to be in bed for work tomorrow. If it makes no sense, I'll take it down and re-post when I get the chance on desktop)