Setting Python locale doesn't work
<p>So I've been trying to set the Python locale. I want to because I want to use the weekday name in local language (using <code>strftime('%A')</code>). But currently the weekday is printed in English even though I tried setting the locale several ways. I am running this on a RPi2 with Ubuntu Mate. </p>

<p>I have tried the solutions in this topic <a href="https://stackoverflow.com/questions/955986/what-is-the-correct-way-to-set-pythons-locale">What is the correct way to set Python&#39;s locale on Windows?</a></p>

<p>I tried explicitly setting locale to <code>nl_NL.utf8</code>:</p>

<pre><code>$&gt; locale -a
$&gt; python3
&gt;&gt;&gt; import locale
&gt;&gt;&gt; locale.setlocale(locale.LC_ALL,'nl_NL.utf-8')
</code></pre>

<p>I also tried setting an empty string, a suggested in the last answer:</p>

<pre><code>&gt;&gt;&gt; locale.setlocale(locale.LC_ALL, '')
</code></pre>

<p>In both cases when I try</p>

<pre><code>&gt;&gt;&gt; locale.getlocale()
</code></pre>

<p>I see <code>nl_NL.utf8</code></p>

<p>But I still get the weekday in English! Haven't been able to find much about this on the internetz except for the above topic and I couldn't get this fixed.</p>

<hr>

<p>Edit:</p>

<p>I have tried all 3 options. The first one returns a weird result:</p>

<pre><code>~/Documenten$ python3
Python 3.4.3+ (default, Oct 14 2015, 16:03:50) 
[GCC 5.2.1 20151010] on linux
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import locale
&gt;&gt;&gt; locale.getlocale(locale.LC_TIME)
(None, None)
&gt;&gt;&gt; locale.setlocale(locale.LC_TIME, 'nl_NL.utf-8')
'nl_NL.utf-8'
&gt;&gt;&gt; locale.getlocale(locale.LC_TIME)
('nl_NL', 'UTF-8')
&gt;&gt;&gt; exit()
jeffrey@jeffrey-desktop:~/Documenten$ python3
Python 3.4.3+ (default, Oct 14 2015, 16:03:50) 
[GCC 5.2.1 20151010] on linux
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import locale
&gt;&gt;&gt; locale.getlocale(locale.LC_TIME)
(None, None)
</code></pre>

<p>It seems like nothing is saved. Am I wrong in assuming you set your locale once and then the system will remember this? The second option:</p>

<pre><code>~/Documenten$ python3
Python 3.4.3+ (default, Oct 14 2015, 16:03:50) 
[GCC 5.2.1 20151010] on linux
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import calendar
&gt;&gt;&gt; calendar.day_name[2]
'Wednesday'
&gt;&gt;&gt; import locale
&gt;&gt;&gt; locale.nl_langinfo(locale.DAY_2)
'Monday'
</code></pre>

<p>Even though I am trying to get a Dutch weekday name I still get an English name in return. Besides that this method starts counting from sunday and not monday. Am I doing anything wrong? The third suggestion got me my weekday name, thanks! But I'm still wondering why the first doesn't work? I am using this script on my own device and would like to work with a correct global locale.</p>

<hr>

<p>Edit2:</p>

<blockquote>
  <p>yes, calling locale.setlocale() in Python does not affect future python processes. Configure environment variables instead, see How to set all locale settings in Ubuntu.</p>
</blockquote>

<p>Ok! So that is why it didn't work. I assumed I had set the locale for any future use in Python, like an environment variable but then only for Python.</p>

<p>I have a bash script creating files and this Python script should delete it after some time (learning to code, didn't know Python when I wrote the Bash script). Bash's "date" method seems to pick up the locale some way or the other. I'll go ahead and see what I can fix for Python. This is what I see when I type <code>$ locale</code>:</p>

<pre><code>LANG=nl_NL.UTF-8
LANGUAGE=nl:en
LC_CTYPE="nl_NL.UTF-8"
LC_NUMERIC="nl_NL.UTF-8"
LC_TIME="nl_NL.UTF-8"
LC_COLLATE="nl_NL.UTF-8"
LC_MONETARY="nl_NL.UTF-8"
LC_MESSAGES="nl_NL.UTF-8"
LC_PAPER="nl_NL.UTF-8"
LC_NAME="nl_NL.UTF-8"
LC_ADDRESS="nl_NL.UTF-8"
LC_TELEPHONE="nl_NL.UTF-8"
LC_MEASUREMENT="nl_NL.UTF-8"
LC_IDENTIFICATION="nl_NL.UTF-8"
LC_ALL=
</code></pre>