Python Forum
Cann't get locale data from IDLE on macOS - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Cann't get locale data from IDLE on macOS (/thread-42123.html)



Cann't get locale data from IDLE on macOS - roomONmoon - May-14-2024

When trying to execute code from IDLE, I can't get the system locale data on macOS

import os
ret = os.popen('locale')
ret.read().split()
['LANG=', 'LC_COLLATE="C"', 'LC_CTYPE="UTF-8"', 'LC_MESSAGES="C"', 'LC_MONETARY="C"', 'LC_NUMERIC="C"', 'LC_TIME="C"', 'LC_ALL=']
But If I'll use bash, I get it

Output:
Air:~ admin$ python3 Python 3.7.9 (default, Jan 3 2021, 01:35:12) [Clang 10.0.0 (clang-1000.10.44.4)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> ret = os.popen('locale') >>> ret.read().split() ['LANG="ru_RU.UTF-8"', 'LC_COLLATE="ru_RU.UTF-8"', 'LC_CTYPE="ru_RU.UTF-8"', 'LC_MESSAGES="ru_RU.UTF-8"', 'LC_MONETARY="ru_RU.UTF-8"', 'LC_NUMERIC="ru_RU.UTF-8"', 'LC_TIME="ru_RU.UTF-8"', 'LC_ALL='] >>>
Why is this happening and how could I get the locales?


RE: Cann't get locale data from IDLE on macOS - deanhystad - May-14-2024

That is the information for the current locale. Maybe you want output from local -a?


RE: Cann't get locale data from IDLE on macOS - roomONmoon - May-14-2024

(May-14-2024, 03:55 PM)deanhystad Wrote: That is the information for the current locale. Maybe you want output from local -a?

Yes, I need the current locale.


RE: Cann't get locale data from IDLE on macOS - roomONmoon - May-14-2024

I need to know about the language of the system in order to automatically set the language in my application, but I can't get this data on macOS, for unknown reasons.


RE: Cann't get locale data from IDLE on macOS - deanhystad - May-14-2024

I don't understand. Those are the settings for the current locale. You are in Russia and you are using UTF8 encoding. What do you want the output to look like? Is the problem that you don't know what the locale codes mean?

Have you looked at using the Python locale module?

https://docs.python.org/3/library/locale.html


RE: Cann't get locale data from IDLE on macOS - roomONmoon - May-14-2024

(May-14-2024, 05:55 PM)deanhystad Wrote: I don't understand. Those are the settings for the current locale. You are in Russia and you are using UTF8 encoding. What do you want the output to look like? Is the problem that you don't know what the locale codes mean?

Have you looked at using the Python locale module?

https://docs.python.org/3/library/locale.html

Okay, this is simple example with locale module: (If you have a macOS, you can repeat it)

1. Open IDLE of python3.10+
2. Past the code
from locale import getlocale
print(getlocale())
3. Try to execute (you'll see empy output locale data)


RE: Cann't get locale data from IDLE on macOS - deanhystad - May-14-2024

What version of OS? What version of Python?


RE: Cann't get locale data from IDLE on macOS - roomONmoon - May-14-2024

(May-14-2024, 06:51 PM)deanhystad Wrote: What version of OS? What version of Python?

macOS Monterey, Python 3.12.3