<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<br>
<blockquote
cite="mid:e4299b1f-c855-4bc9-9e61-3006172410dc@l28g2000yqh.googlegroups.com"
type="cite">
<pre wrap="">1. Is there a way for writing portable Python code dealing with
locales
(as sketched in the beginning)?
</pre>
</blockquote>
I usually do this at the top of my main program, before importing
other modules:<br>
<br>
import locale<br>
locale.setlocale(locale.LC_ALL, '')<br>
<br>
<br>
This is absolutely portable. The above snippet works for different
operating systems with different default encodings. You can always
setup some environment variable before starting up the program if
you really have to. And yes, that setting will be OS dependent, but
your program will still be portable.<br>
<br>
I have no access to Croatian Windows, but I bet that the above code
would set the locale to the correct thing on both Linux and Windows.<br>
<br>
It would be a bad idea to set the locale from anywhere else than
your main program anyway. There are also some notes in the docs
about this (
<a class="moz-txt-link-freetext" href="http://docs.python.org/library/locale.html#locale.setlocale">http://docs.python.org/library/locale.html#locale.setlocale</a> ):<br>
<br>
<blockquote type="cite">
<p><a title="locale.setlocale" class="reference internal"
href="http://docs.python.org/library/locale.html#locale.setlocale"><tt
class="xref docutils literal"><span class="pre">setlocale()</span></tt></a>
is not thread-safe on most systems. Applications typically
start with a call of</p>
<div class="highlight-python">
<div class="highlight">
<pre><span class="kn">import</span> <span class="nn">locale</span>
<span class="n">locale</span><span class="o">.</span><span class="n">setlocale</span><span class="p">(</span><span class="n">locale</span><span class="o">.</span><span class="n">LC_ALL</span><span class="p">,</span> <span class="s">''</span><span class="p">)</span>
</pre>
</div>
</div>
<p>This sets the locale for all categories to the user’s default
setting (typically
specified in the <span class="target" id="index-429"></span><strong
class="xref">LANG</strong> environment variable). If the
locale is not
changed thereafter, using multithreading should not cause
problems.</p>
</blockquote>
<br>
Why are you trying to force a specific locale to your program
anyway?<br>
<br>
L<br>
<br>
<br>
</body>
</html>