Python: date formatted with %x (locale) is not as expected
Question: I have a datetime object, for which I want to create a date string according
to the OS locale settings (as specified e.g. in Windows'7 region and language
settings).

Following Python's [datetime formatting
documentation](http://docs.python.org/library/datetime.html#strftime-and-
strptime-behavior), I used the `%x` format code which is supposed to output
"_Locale’s appropriate date representation._ ". I expect this "representation"
to be either Windows "short date" or "Long date" format, but it isn't either
one. (I have the short date format set to `d/MM/yyyy` and the long date format
to `dddd d MMMM yyyy`, but the output is `dd/MM/yy`)

What's wrong here: the Python documentation, the Python implementation, or my
expectation ? (and how to fix?)


Answer: After reading the [setlocale()
documentation](http://docs.python.org/library/locale.html#locale.setlocale), I
understood that the default OS locale is not used by Python as the default
locale. To use it, I had to start my module with:

    
    
    import locale
    locale.setlocale(locale.LC_ALL, '')
    

Alternatively, if you intend to only reset the locale's time settings, use
just `LC_TIME` as it breaks many fewer things:

    
    
    import locale
    locale.setlocale(locale.LC_TIME, '')
    

Surely there will be a valid reason for this, but at least this could have
been mentioned as a remark in the Python documentation for the %x directive.

