Python - Get Instance Variables
Posted
by
Chris Bunch
on Stack Overflow
See other posts from Stack Overflow
or by Chris Bunch
Published on 2008-09-20T19:30:24Z
Indexed on
2010/12/23
21:54 UTC
Read the original article
Hit count: 359
Is there a built-in method in Python to get an array of all a class' instance variables? For example, if I have this code:
class hi:
def __init__(self):
self.ii = "foo"
self.kk = "bar"
Is there a way for me to do this:
>>> mystery_method(hi)
["ii", "kk"]
Thanks guys!
Edit: I originally had asked for class variables erroneously. Thanks to all who brought this to my attention!
© Stack Overflow or respective owner