Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python print class variables

# to print out the variable names
print(vars(YourClass))

# to print out names and values
for var in vars(YourClass):
    print(getattr(YourClass, var))
Comment

print class python

class yourClass:
    def __str__(self):
        return "value"  #replace value with what you want to print
Comment

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()))
Comment

PREVIOUS NEXT
Code Example
Python :: pip install qrcode python 
Python :: append path to sys jupyter notebook 
Python :: python send image in post request with json data 
Python :: Make a basic pygame window 
Python :: set seed tensorflow 
Python :: sort arr python 
Python :: flask api abort 
Python :: how to start an exe file in python 
Python :: prime number in python 
Python :: get only every 2 rows pandas 
Python :: plt.imread python 
Python :: python array from 1 to n 
Python :: place legend on location matplotlib 
Python :: print boolean in python 
Python :: ban command in discord.py 
Python :: python try except 
Python :: how to rename rengeindex pandas 
Python :: how to use elif in python 
Python :: python plotting moving average 
Python :: python define random variables name 
Python :: python string slicing 
Python :: python ip address is subnet of 
Python :: python-telegram-bot 
Python :: copy directory from one location to another python 
Python :: how to check if there are duplicates in a list python 
Python :: default flask app 
Python :: ordereddict 
Python :: how to edit messages in discord . py 
Python :: filter query objects by date range in Django? 
Python :: click ok on alert box selenium webdriver python 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =