Discover instance variables
Bjoern Schliessmann
usenet-mail-0306.20.chr0n0ss at spamgourmet.com
Wed Jul 18 09:29:21 EDT 2007
JonathanB wrote:
> So given that example, is there a clean way to get this output:
>
> Data for Earth:
> Name = Earth
> WTN = 5.0
> Ag = 0
> Na = 0
> ...
> ...
> Notes = None
Sure, save the __init__ parameters explicitly in a dict.
self.data = {"Name": name,
"WTN": WTN,
"Ag": Ag,
...
}
To display them, you can iterate through the dict:
print "Data for Earth:"
for field, content in self.data.items():
print "%s = %r" % field, content
Hope that helps.
Regards,
Björn
--
BOFH excuse #188:
..disk or the processor is on fire.
More information about the Python-list
mailing list