Python Forum
Cann't get locale data from IDLE on macOS
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cann't get locale data from IDLE on macOS
#1
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?
Reply
#2
That is the information for the current locale. Maybe you want output from local -a?
Reply
#3
(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.
Reply
#4
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.
Reply
#5
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
Reply
#6
(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)
Reply
#7
What version of OS? What version of Python?
Reply
#8
(May-14-2024, 06:51 PM)deanhystad Wrote: What version of OS? What version of Python?

macOS Monterey, Python 3.12.3
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python installation for old MacOS Yonix 1 583 Sep-21-2023, 03:32 PM
Last Post: menator01
  Why is IDLE not opening on a MacOS Montery 12.6 and using Python 3.10.7? Merlin385 7 1,861 Oct-08-2022, 08:36 PM
Last Post: Merlin385
Lightbulb MacOS can't make it Archi 1 1,301 May-29-2022, 07:38 AM
Last Post: Larz60+
  Text widget -macOS apffal 1 1,828 Sep-23-2021, 10:12 PM
Last Post: apffal
  Installing Python3 on MacOS using brew zazas321 5 5,426 May-28-2021, 06:19 AM
Last Post: perfringo
  can't open excel with my macos dcc 0 2,447 Oct-30-2019, 04:18 AM
Last Post: dcc
  IDLE not importing pygame (ok outside of IDLE) miner_tom 1 3,402 Sep-14-2018, 07:54 PM
Last Post: Larz60+
  pymysql on macos seirra tony1812 5 4,684 Sep-17-2017, 03:24 PM
Last Post: Larz60+
  Python IDLE 3.6.2 on WIn7 vs Pyhton 3 IDLE raspberry djdan_23 5 5,812 Sep-07-2017, 12:51 PM
Last Post: Larz60+
  rounding locale.currency birdieman 8 10,835 Dec-28-2016, 01:48 AM
Last Post: birdieman

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020