get object attributes python
for att in dir(your_object):
print (att, getattr(your_object,att))
get object attributes python
for att in dir(your_object):
print (att, getattr(your_object,att))
python get attributes of object
getattr(object, 'attribute_name')
how to get list of all instance in class python
import weakref
class MyClass:
_instances = set()
def __init__(self, name):
self.name = name
self._instances.add(weakref.ref(self))
@classmethod
def getinstances(cls):
dead = set()
for ref in cls._instances:
obj = ref()
if obj is not None:
yield obj
else:
dead.add(ref)
cls._instances -= dead
a = MyClass("a")
b = MyClass("b")
c = MyClass("c")
del b
for obj in MyClass.getinstances():
print obj.name # prints 'a' and 'c'
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us