Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to print class attributes in python

an = Animal()
attrs = vars(an)
# {'kids': 0, 'name': 'Dog', 'color': 'Spotted', 'age': 10, 'legs': 2, 'smell': 'Alot'}
# now dump this in some way or another
print(', '.join("%s: %s" % item for item in attrs.items()))
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #print #class #attributes #python
ADD COMMENT
Topic
Name
2+1 =