Converting DD MM YYYY into YYYY-MM-DD?

Rami Chowdhury rami.chowdhury at gmail.com
Tue Aug 18 04:42:26 EDT 2009


> Python doesn't like the above:
>
> #locale.Error: unsupported locale setting
> locale.setlocale(locale.LC_ALL, ('FR', 'UTF-8'))
>
> Maybe it was introduced in more recent versions of Python?
Hmm, that's odd. According to the docs 
(http://docs.python.org/library/locale.html#locale.setlocale) it's been that 
way since 2.0, but I've just checked this on my Windows (Vista) machine and 
you're right, it returns an error. 

This worked for me on 32-bit Vista:

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

It uses Windows-1252 for the encoding, but that seems to deal with the 
circonflexe in 'Août' just fine, so it should work for this purpose.


----
Rami Chowdhury
"Never attributed to malice that which can be attributed to stupidity." -- 
Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)

On Tuesday 18 August 2009 01:19:53 Gilles Ganault wrote:
> On Tue, 18 Aug 2009 01:11:20 -0700, Rami Chowdhury
>
> <rami.chowdhury at gmail.com> wrote:
> >Could you let me know which platform this is on (Windows, *nix)? It may be
> > a locale encoding issue -- the locale.setlocale() function allows the
> > second argument to be a tuple of (locale_code, encoding), as below:
> >
> >locale.setlocale(locale.LC_ALL, ('FR', 'UTF-8'))
>
> It's on XP, and I'm using ActivePython 2.5.1.1.
> http://www.activestate.com/activepython/
>
> Python doesn't like the above:
>
> #locale.Error: unsupported locale setting
> locale.setlocale(locale.LC_ALL, ('FR', 'UTF-8'))
>
> Maybe it was introduced in more recent versions of Python?
>
> >Since this is for a one-shot (and presumably threading-agnostic) program,
> > and a fairly trivially formatted date-string, I would suggest using
> >datetime.strptime
> >(http://docs.python.org/library/datetime.html#datetime.datetime.strptime)
> > and not regular expressions (which IIRC have Issues with non-ASCII
> > characters).
>
> If the regex library can only handle basic latin characters, I'll wait
> until a script I'm running is done, and I'll upgrade to the 2.6.2.2 to
> see how it goes.
>
> Thank you.




More information about the Python-list mailing list