Setting the locale and string module in Python

This simple script:

from locale import LC_ALL, setlocale print setlocale(LC_ALL,"") from string import letters print letters 

gives me this result:

 tr_TR.utf8 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 

And, here: http://docs.python.org/library/string.html?highlight=string#string.letters , it says that this value is language dependent and is updated when setlocale is called. However, I do not see a single letter from my language. Is there a way to get a list of letters for the current locale?

+2
source share
1 answer

I had to explicitly set the locale to Turkish, as this is not the default on my computer, but seems to work more or less:

 > python Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from locale import LC_ALL, setlocale >>> print setlocale(LC_ALL,"Turkish") Turkish_Turkey.1254 >>> from string import letters >>> print letters abcdefghijklmnopqrstuvwxyzƒsoªµºßàáâaäåæçèéêëìíîïgñòóôoöoùúûüisÿ... ABCDEFGHIJKLMNOPQRSTUVWXYZSOYAAAAÄÅÆÇEÉEEIIIIGÑOOOOÖOUUUÜIS >>> 

The result basically looks correct (AFAIK), except for the inclusion of Q, W, and X, which of this in the Wikipedia articles aren 't part of the Turkish alphabet.

Update:

To better replicate your environment, I first used the Language and Regional Standards control panel and changed my region to Turkish, which would make it the default for setlocale . Indeed, however, the list of letters still looks OK - so I cannot reproduce your problem.

One difference this time is that before starting python, I first switched to the console code page on Windows ANSI Turkish 1254 to enable the correct output of the character from the alphabet. This led to the last two letters of the output display being correctly displayed, however they also contain the letters Q, W and X, which are not part of the alphabet (and maybe there, of my choice).

 C:\>chcp 1254 Active code page: 1254 C:\>python Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from locale import LC_ALL, setlocale >>> print setlocale(LC_ALL,"") Turkish_Turkey.1254 >>> from string import letters >>> print letters abcdefghijklmnopqrstuvwxyzƒšœªµºßàáâãäåæçèéêëìíîïğñòóôõöøùúûüışÿ... ABCDEFGHIJKLMNOPQRSTUVWXYZŠŒŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏĞÑÒÓÔÕÖØÙÚÛÜİŞ >>> 
+2
source

Source: https://habr.com/ru/post/1258814/


All Articles