Python Forum
[SOLVED] [Windows] Converting filename to UTF8?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] [Windows] Converting filename to UTF8?
#2
Keep it uft-8 all the way,make sure editor don't mess it when save stuff.
Can test files with chardetect.
G:\div_code\answer
λ chardetect pla.kml
pla.kml: utf-8 with confidence 0.99
Example:
from bs4 import BeautifulSoup

"""
<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
 <Document>
    <Placemark>
     Μῆνιν ἄειδε
    </Placemark>
    <Placemark>
     異體字字
    </Placemark>
 </Document>
</kml>
"""

soup = BeautifulSoup(open('pla.kml', encoding='utf-8'), 'xml')
mark = soup.find_all('Placemark')
print(mark)

with open('pla_out.kml', "w", encoding='utf-8') as fp:
    fp.write(soup.prettify(formatter=None))
Output:
[<Placemark>Μῆνιν ἄειδε</Placemark>, <Placemark>異體字字</Placemark>]
pla_out.kml
Output:
<?xml version="1.0" encoding="utf-8"?> <kml xmlns="http://www.opengis.net/kml/2.2"> <Document> <Placemark> Μῆνιν ἄειδε </Placemark> <Placemark> 異體字字 </Placemark> </Document> </kml>
Reply


Messages In This Thread
RE: [Windows] Converting filename to UTF8? - by snippsat - Sep-06-2022, 05:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] [Windows] Fails reading strings with accents Winfried 1 883 Apr-23-2023, 05:27 PM
Last Post: Larz60+
  [SOLVED] [Windows] Right way to prompt for directory? Winfried 4 2,131 Jan-17-2023, 09:28 PM
Last Post: markoberk
  Who converts data when writing to a database with an encoding different from utf8? AlekseyPython 1 2,410 Mar-04-2019, 08:26 AM
Last Post: DeaD_EyE
  Want a list utf8 formatted but bytestrings found nikos 28 11,748 Feb-18-2019, 08:26 AM
Last Post: nikos
  SOLVED: best way to block (wait on) shell calls to multiple windows programs at once? ezdev 0 2,639 Dec-10-2017, 06:42 AM
Last Post: ezdev
  [?] UTF8, Unicode and Binary data reading troubles doublezero 1 3,203 Mar-31-2017, 11:32 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020