I am trying tot write a file and remove the .pdf extension and replacing it with .xml extension.
But now, if the filename starts or ends with the letter p, it gets removed.
tree = ET.ElementTree(root).write(base_dir+str(file_name).strip(‘.pdf’)+".xml", method=’xml’, encoding=’UTF-8′, xml_declaration=True)
So filename help.pdf will be writen as hel.xml
or press.pdf will be writen as ress.xml
if i remove .strip(‘.pdf’) from the line it doesn’t remove the p, but ofcourse it will write .pdf.xml
i hope someone can help me.
Greets Dyllan
>Solution :
strip removes any leading or trailing sequence composed of any of the characters included in the specified string. You want to use e.g. replace(".pdf", "") instead. Or better, do replace(".pdf", ".xml") and remove that +".xml".