alphabet_dic = ['a','b','c','d','e','f','g','h','i','j','k','l','n','o','p','q','r','s','t','u','v','w','y','z','m']
doc = Document('template.docx')
firstSen = doc.paragraphs[0].text
rep_dic = {ord(k):None for k in c_dic + [x.upper() for x in c_dic]}
translation = (firstSen.translate(rep_dic))
doc.save('translation.docx')
I'm trying to erase a range of characters in a document, but what I am doing doesn't work. I tested my code with a regular string and it worked fine, but once I applied it to the document, it didn't budge at all. No letters were erased.
Any suggestions for a better solution or direction?
As Jean-François Fabre said you're not changing the document, so you need to write the line to the document before saving, like this:
doc.paragraphs[0].text = translation
doc.save('translation.docx')