[Tutor] Listing all of an instances variables

Matt Williams matthew.williams at cancer.org.uk
Sat Oct 8 16:51:25 CEST 2005


Dear List,

I'm stuck on trying to write a generic 'report' function:

Class SomeClass:
   def __init__(self,a,b):
	self.a = a
	self.b = b

   def report(self):
	for i in dir(self):
	    print self.i

<Error Traceback......>


This is where I run into problems: How do I return all of the variables
in an instance?

I'm sure I'm not the first person to ask, but I couldn't find an answer
anywhere else...

Thanks,

Matt
-- 
Dr. M. Williams MRCP(UK)
Clinical Research Fellow
Cancer Research UK
+44 (0)207 269 2953
+44 (0)7384 899570



More information about the Tutor mailing list