I have a csv with email addresses that needs to be hashed in MD5 format, then save the hashed emails as a new csv. I haven't seen my exact use case on SO and haven't been able to successfully modify existing questions.
Original file path is "/Users/[username]/Downloads/email_original.csv" and desired output file would be "/Users/[username]/Downloads/email_hashed.csv".
Original File
email_addr
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
Hashed File
email_addr
0x3731BF23851200A7607BA554EEAF7912
0xA5D5D3B99896D32BAC64162BD56BE177
0xAE03858BDFBDF622AF5A1852317500C3
0xC870F8D75180AC9DA2188129C910489B
0xD7AFD8085548808459BDEF8665C8D52A
The answer in your comment is nearly correct. You only need to open another file with the write attribute w. I have changed your query to use with so you don't to have to explicitly close the file handlers:
with open("/Users/[username]/Downloads/email_original.csv",'rb') as file:
with open("/Users/[username]/Downloads/email_hashed.csv",'w') as output:
for line in file:
line=line.strip()
print hashlib.md5(line).hexdigest()
output.write(hashlib.md5(line).hexdigest() +'\n')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With