locale settings and date parsing under windows

Discussion in 'Python' started by AlienBaby, Feb 3, 2011.

  1. AlienBaby

    AlienBaby Guest

    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.
    AlienBaby, Feb 3, 2011
    #1
    1. Advertising

  2. AlienBaby

    AlienBaby Guest

    On Feb 3, 10:22 am, AlienBaby <> wrote:
    > 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.
    AlienBaby, Feb 3, 2011
    #2
    1. Advertising

  3. On 02/03/11 10:59, AlienBaby wrote:
    > On Feb 3, 10:22 am, AlienBaby<> wrote:
    >> 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.


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

    --
    mph
    Martin P. Hellwig, Feb 3, 2011
    #3
  4. AlienBaby

    AlienBaby Guest

    On Feb 3, 12:13 pm, "Martin P. Hellwig" <>
    wrote:
    > On 02/03/11 10:59, AlienBaby wrote:
    >
    >
    >
    >
    >
    > > On Feb 3, 10:22 am, AlienBaby<>  wrote:
    > >> 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.

    >
    > You might also want to have a look at the contents of:
    > locale.locale_alias
    >
    > --
    > mph- Hide quoted text -
    >
    > - Show quoted text -


    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.
    AlienBaby, Feb 3, 2011
    #4
  5. AlienBaby

    Guest

    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
    , Feb 3, 2011
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maurice Hulsman
    Replies:
    1
    Views:
    1,819
    Guus Bosman
    Jul 25, 2004
  2. Gabriel Genellina
    Replies:
    0
    Views:
    681
    Gabriel Genellina
    Feb 18, 2009
  3. Rakesh
    Replies:
    2
    Views:
    1,951
    Roedy Green
    Apr 3, 2009
  4. donet programmer
    Replies:
    3
    Views:
    1,518
    Gregory A. Beamer
    Nov 20, 2009
  5. zade
    Replies:
    1
    Views:
    591
    James Kanze
    Mar 5, 2010
Loading...

Share This Page