How to avoid encoding parameter when opening file in Python3
<p>When I am working on a .txt file on a Windows device I must save as either: ANSI, Unicode, Unicode big endian, or UTF-8. When I run Python3 on an OSX device and try to import and read the .txt file, I have to do something along the lines of:</p>

<pre><code>with open('ships.txt', 'r', encoding='utf-8') as f:
    for line in f.readlines():
        print(line)
</code></pre>

<p>Is there a particular format I should use to encode the .txt file on the Windows device to avoid adding the encoding parameter when opening the file in Python?</p>

<p>Call <code>locale.getpreferredencoding(False)</code> on your OSX device.  That's the default encoding used for reading a file on that device.  Save in that encoding on Windows and you won't need to specify the encoding on your OSX device.</p>

<p>But as the <a href="https://www.python.org/dev/peps/pep-0020/" rel="nofollow">Zen of Python</a> says, "Explicit is better than implicit."  Since you know the encoding, why not specify it?</p>

python unicode encoding python-import