Latest recipes tagged "mazovia"http://code.activestate.com/recipes/tags/mazovia/new/2012-02-15T09:24:13-08:00ActiveState Code RecipesMazovia encoding for Polish text from MS-DOS era (Python)
2012-02-15T09:24:13-08:00Michal Niklashttp://code.activestate.com/recipes/users/186902/http://code.activestate.com/recipes/578040-mazovia-encoding-for-polish-text-from-ms-dos-era/
<p style="color: grey">
Python
recipe 578040
by <a href="/recipes/users/186902/">Michal Niklas</a>
(<a href="/recipes/tags/encoding/">encoding</a>, <a href="/recipes/tags/mazovia/">mazovia</a>, <a href="/recipes/tags/polish/">polish</a>).
</p>
<p>Some MS-DOS era text or databases in Poland use Mazovia encoding for letters such as: ą, ę, ś, ż, ź. It is very well described on Polish wikipedia: <a href="http://pl.wikipedia.org/wiki/Mazovia_%28kod%29" rel="nofollow">http://pl.wikipedia.org/wiki/Mazovia_(kod)</a></p>
<p>There is <code>mazovia.py</code> with Polish encoding. Copy it to the Python <code>Lib/encodings</code> directory. Tested with Python 2.7. For Python 3.2 I had to remove unicode string u prefix.</p>
<p>Usage:</p>
<pre class="prettyprint"><code>def conv_file(fname):
f = codecs.open(fname, 'rb', 'mazovia')
s = f.read()
f.close()
f = codecs.open(fname + '_utf8', 'wb', 'utf8')
f.write(s)
f.close()
</code></pre>