[Tutor] dictionary manipulation
Chris Hallman
challman at gmail.com
Wed Jul 26 17:45:23 CEST 2006
I need some suggestions on how to work with a dictionary. I've got a program
that builds a dictionary. I need to be able to manipulate the different keys
and data so that I can write the output to a file AND utilize the smtplib to
send the data in an email. I had problems using the data in the dictionary,
so I wrote a crude for loop to strip characters:
>>> print result
{'s0100swa': ['running correct IOS'], 's0300swa': ['INCORRECT running IOS'],
's0200swa': ['running correct IOS'], 's0400swa': ['running correct IOS']}
results= sorted(result.items())
>>> print results
[('s0100swa', ['running correct IOS']), ('s0200swa', ['running correct
IOS']), ('s0300swa', ['INCORRECT running IOS']), ('s0400swa', ['running
correct IOS'])]
for x in range(len(results)):
text = repr(results[x])
text = text.replace("'", "")
text = text.replace("(", "")
text = text.replace(")", "")
text = text.replace("[", "")
text = text.replace("]", "")
text = text.replace(",", ":")
output.write(text + "\n")
output.flush()
output.write("\n")
I need to remove the extra characters so the file and email output isn't
difficult to read. I also need to be able to use the dictionary data so that
I can compose the message used by the smtplib.
Any suggestions?
Thanks!!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060726/15891fc1/attachment.html
More information about the Tutor
mailing list