Hello,<br><br>I have a class and i return both a key list and dictionary from the class. Is it good form to do this? The print helo.__dict__ shows both the list and dictionary.<br><br><br><br>>>> class Parse_Nagios_Header:<br>
... def __init__(self):<br>... self.keylist = []<br>... self.d = {}<br>... f = open("common.h") <br>... lines = f.readlines()<br>... lines = filter(lambda x: not x.isspace(), lines)<br>
... f.close()<br>... for line in lines:<br>... if re.search("CMD", line):<br>... line = line.lstrip('#define ')<br>... line = line.strip()<br>... line.replace('\t', ' ')<br>
... line = line.split()<br>... if len(line) > 2:<br>... pass<br>... elif len(line) == 2:<br>... line[1] = int(line[1])<br>... self.d[line[1]] = line[0]<br>
... self.keylist = sorted(self.d.iterkeys())<br>... def __iter__(self):<br>... return iter(self.keylist, self.d)<br>... <br>>>> helo = Parse_Nagios_Header()<br>>>> print helo<br><__main__.Parse_Nagios_Header instance at 0x7fbf5b09b488><br clear="all">
>>> for key in helo.keylist:<br>... print "Key:%s Value:%s" %(key,helo.d[key])<br>... <br>Key:0 Value:CMD_NONE<br>Key:1 Value:CMD_ADD_HOST_COMMENT<br>Key:2 Value:CMD_DEL_HOST_COMMENT<br>Key:3 Value:CMD_ADD_SVC_COMMENT<br>
Key:4 Value:CMD_DEL_SVC_COMMENT<br>Key:5 Value:CMD_ENABLE_SVC_CHECK<br><br>-- <br>David Garvey<br>