The code works well and does what I intend for it to do. In essence, it opens a file referenced as 'resource'. This is a .csv file. I then searches for the keys in the dictionary and for each key that it encounters, it replaces it with the value - the dictionary being 'rep'. It then exports this to a new .csv file.
The above just seems slightly cumbersome and so I just wonder if there is a slicker / more pythonistic way of achieving the above? I think the non-slick part of my code is the writing of the amended data to a new file but I seek any feedback regarding improving my code.
with open(resource,'rb') as f:
data = f.read()
rep = {"Incoming Call" : "Voice (in)",
"Outgoing Call" : "Voice (out)",
"Incoming SMS" : "SMS (in)",
"Outgoing SMS" : "SMS (out)"}
for i, j in rep.iteritems():
print i, j
data = data.replace(i, j)
with open("output.txt", "w") as outputfile:
outputfile.write(data)
outputfile.close()