Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7682807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:39:11+00:00 2026-05-31T18:39:11+00:00

Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32.

  • 0

Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32.

>>> locale.getdefaultlocale()
('ru_RU', 'cp1251')  #ok, Russian locale is set, as per user settings
>>> a  = datetime.date.today()
>>> a.strftime("%B %d")
March 22' #ouch, that's not Russian.
>>> locale.setlocale(locale.LC_ALL, 'russian_russia')
'Russian_Russia.1251'
>>> a.strftime("%B %d")
'Март 22' #now it's ok

So… Why doesn’t it work without resetting the default locale? Is it OS related? Is there a way to do something like locale.setlocale(convert_it_somehow(locale.getdefaultlocale()))? All I want to do is to display dates according to user’s preference. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:39:13+00:00Added an answer on May 31, 2026 at 6:39 pm

    The thing to realize about locales is that Python, as a programming language implementation rather than an application, can’t assume whether the environments locale setting (through the LANG and LC_* environment variables) should be applied to a program written in Python or not. So, Python does not set the locale. Your program has to do so explicitly. Python does parse the locale variables for you, and that’s what locale.getdefaultlocale() returns: the default locale as specified by the environment.

    The active locale, the one actually used, is returned by locale.getlocale(), and if you run that before explicitly setting the locale you will see it returns (None, None) (to indicate that no locale is set.) If you want your application to use the default locale specified by the environment, you have to call locale.setlocale(locale.LC_ALL, ''). (The empty string means “whatever is the default”, and is unfortunately different from None or not passing the argument.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32
I get the following results on my machine: Python 3.2.2 (default, Sep 4 2011,
Ubuntu 11.10: $ python Python 2.7.2+ (default, Oct 4 2011, 20:03:08) [GCC 4.6.1] on
Do the following on the default Python install on Mac OS X 10.5 (Leopard)
I use Python 2.6 more than I use Leopard's default python installation, so I
I'd like to how to upgrade the default python installation(2.5.2) supplied with ubuntu 8.04
Is output buffering enabled by default in Python's interpreter for sys.stdout ? If the
Python's subprocess module by default passes all open file descriptors to any child processes
Python for Windows by default comes with IDLE, which is the barest-bones IDE I've
I know python functions are virtual by default. Let's say I have this: class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.