simple question about classes

Scott Hathaway scott_hathaway at riskvision.com
Mon Aug 13 16:20:48 EDT 2001


If I have a class, is there a way to iterate through the name of all of the
properties (public variables) of the class which would include public vars
that were added at the time of instantiation?

class a():
    getPublicVars(self):
        # loop here that prints each variable and it's value


myClassVar = a()
myClassVar.color = 'red'
myClassVar.style='antique'
myClassVar.getPublicVars()

Can this be done (I realize that it is probably very simple)?  If so, can
someone give me a code snippet that does the loop above?


Thanks,
Scott





More information about the Python-list mailing list