locale settings and date parsing under windows

A

AlienBaby

Hi,

I'm attempting to convert some date-time strings from a text file
under windows into a datetime object as returned by strptime()

However, the strings can represent dates in various formats based on
the country of origin, for example shortened month names etc.. are
different between countries.

I am trying to set the correct locale for strptime to work, but I'm
having a lot of trouble doing this under windows.


IE, wher the date is in the Danish Language,

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

gives

locale.Error: unsupported locale string.

I have tried various ways but always hit the same error.

I understand setting LC_ALL may not be what I require, I was first
looking to simply get the locale setting correctly before I started
changing only the date-time specific elements.



Any help or pointers much appreciated. Current searching around is
revealing a fair amount of confusion..!


Thanks,

Matt.
 
A

AlienBaby

Hi,

I'm attempting to convert some date-time strings from a text file
under windows into a datetime object as returned by strptime()

However, the strings can represent dates in various formats based on
the country of origin, for example shortened month names etc.. are
different between countries.

I am trying to set the correct locale for strptime to work, but I'm
having a lot of trouble doing this under windows.

IE, wher the date is in the Danish Language,

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

gives

locale.Error: unsupported locale string.

I have tried various ways but always hit the same error.

I understand setting LC_ALL may not be what I require, I was first
looking to simply get the locale setting correctly before I started
changing only the date-time specific elements.

Any help or pointers much appreciated. Current searching around is
revealing a fair amount of confusion..!

Thanks,

Matt.

As often happens, writing that out and the working through a bit more,
I resolved my own question.

It ended up being a simple matter of translating from posix codes to
windows codes, so 'fr_FR' becomes 'French_France'...

thanks,

MAtt.
 
M

Martin P. Hellwig

As often happens, writing that out and the working through a bit more,
I resolved my own question.

It ended up being a simple matter of translating from posix codes to
windows codes, so 'fr_FR' becomes 'French_France'...

thanks,

MAtt.

You might also want to have a look at the contents of:
locale.locale_alias
 
A

AlienBaby

You might also want to have a look at the contents of:
locale.locale_alias

I did for a bit..

I tried, for example with French

from locale.locale_alias, you can find

'fr_FR' aliases to 'fr_FR.ISO8859-1'

but trying,

locale.setlocale(locale.LC_ALL,'fr_FR.ISO8859-1')

gives

locale.Error: unsupported locale setting


I'm now just using a handbuilt dict that holds translations like

'fr_FR' : 'French_France'
'da_DK' : 'Danish_Denmark'

etc..

Thanks,

MAtt.
 
P

python

Matt,
I'm now just using a handbuilt dict that holds translations like

'fr_FR' : 'French_France'
'da_DK' : 'Danish_Denmark'

What sources are you using for your dict keys and dict values? I'm
struggling with the same issue and I'm looking for master references for
both sets of code.

Thank you,
Malcolm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top