<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic PSA: For those of you using pathlib for file manipulation in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/psa-for-those-of-you-using-pathlib-for-file/m-p/1639736#M74581</link>
    <description>&lt;P&gt;I was just banging my head against a wall for a couple hours trying to figure out why all my text was being written back into my project using&amp;nbsp;cp1252 encoding. Turns out that if you use the Path.open() method to read a file, it will defer to your system for text encoding. In the case of Windows, that is still cp1252 and not utf-8 even though all userspace text in Windows has been utf-8 for a few years. This was a nefarious bug since ASCII, cp1252, and UTF-8 are all interchangeable for English letters and punctuation. it wasn't until a field contained the&amp;nbsp;• symbol and I got back&amp;nbsp;â€¢ that I noticed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Fix:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;-- Path('&amp;lt;filepath&amp;gt;').open('wt').write(my_string)
++ Path('&amp;lt;filepath&amp;gt;').open('wt', encoding='utf-8').write(my_string)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note:&lt;/P&gt;&lt;P&gt;Files will remember the encoding they were created in, so make sure you don't have any files containing unicode that are actually encoded as&amp;nbsp;cp1252 or you'll be kicking yourself.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 06 Aug 2025 16:50:18 GMT</pubDate>
    <dc:creator>HaydenWelch</dc:creator>
    <dc:date>2025-08-06T16:50:18Z</dc:date>
    <item>
      <title>PSA: For those of you using pathlib for file manipulation</title>
      <link>https://community.esri.com/t5/python-questions/psa-for-those-of-you-using-pathlib-for-file/m-p/1639736#M74581</link>
      <description>&lt;P&gt;I was just banging my head against a wall for a couple hours trying to figure out why all my text was being written back into my project using&amp;nbsp;cp1252 encoding. Turns out that if you use the Path.open() method to read a file, it will defer to your system for text encoding. In the case of Windows, that is still cp1252 and not utf-8 even though all userspace text in Windows has been utf-8 for a few years. This was a nefarious bug since ASCII, cp1252, and UTF-8 are all interchangeable for English letters and punctuation. it wasn't until a field contained the&amp;nbsp;• symbol and I got back&amp;nbsp;â€¢ that I noticed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Fix:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;-- Path('&amp;lt;filepath&amp;gt;').open('wt').write(my_string)
++ Path('&amp;lt;filepath&amp;gt;').open('wt', encoding='utf-8').write(my_string)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note:&lt;/P&gt;&lt;P&gt;Files will remember the encoding they were created in, so make sure you don't have any files containing unicode that are actually encoded as&amp;nbsp;cp1252 or you'll be kicking yourself.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Aug 2025 16:50:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/psa-for-those-of-you-using-pathlib-for-file/m-p/1639736#M74581</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-08-06T16:50:18Z</dc:date>
    </item>
  </channel>
</rss>

