Answers for "loop thru object attributes and access them in python"

4

loop through python object

for attr, value in k.__dict__.items():
        print(attr, value)
Posted by: Guest on February-29-2020
0

iterate through attributes of class python

L = [[getattr(self, attr), attr] for attr in dir(self) if not attr.startswith("__")]
Posted by: Guest on November-23-2020

Python Answers by Framework

Browse Popular Code Answers by Language