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!!
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to