Lyend Victorian Lyend Victorian - 1 month ago 4x
Python Question

Python: listing variables from object

So basically I need help with laziness.

Is it possible in python to take an object, and then list off all it's variables

For example

class some_object:
def __init__(self):
self.Name = None
self.UUID = None

then call a magic function that lists all the variable names in the object

and maybe return something that looks close to this:

[some_object.Name, some_object.UUID]

Keep in mind I DON'T NEED the values attached to the object, but rather the name of the variable, such as Name and UUID

if anyone could help me, that'd be awesome.

Thanks for everyone answering my question, the magic function I needed was vars (). I really appreciate everyone effort and input on the problem


You can use vars():

class about_me:
  def __init__(self): = "Lyend Victorian"
    self.age = "25"
    self.height = "180"

me = about_me()

>>> vars(me)
{'age': '25', 'name': 'Lyend Victorian', 'height': '180'}