Hello,
On Windows, I need to loop through a list of filenames, and use them into UTF8 documents.
Problem is, some might contain characters, and I get garbage (because of 1252?).
This doesn't work:
Thank you.
On Windows, I need to loop through a list of filenames, and use them into UTF8 documents.
Problem is, some might contain characters, and I get garbage (because of 1252?).
This doesn't work:
import pathlib PATH=pathlib.Path(item).parent BASENAME = pathlib.Path(item).stem #NO CHANGE BASENAME.encode('UTF-8') print("BASENAME is",BASENAME) soup = BeautifulSoup(open(item, 'r'), 'xml') name = soup.select_one("kml > Document > name") if name: name.string = BASENAME else: name = soup.new_tag("name") name.string = BASENAME doc = soup.select_one("kml > Document") doc.insert(0,name) with open(OUTPUTFILE, "w") as file: file.write(soup.prettify(formatter=None))How can I convert Windows filenames into UTF8?
Thank you.