time.strptime()

Hello,

I’m fairly new to python and wxpython and the whole object-oriented programming.
I tought I was doing fine until I ran into a problem with time.strptime()

I have attached a little test script.

I’m wondering why the first (lower) time.strptime works and the second one gives a ValueError - do I need to something special to get this working?

This is python 2.6.5 (release26) on Gentoo linux.

Thanks for your help!

test.py (573 Bytes)

This works just fine on Windows XP, wxPython 2.8.10.1, Python 2.5.
Personally, I don't see any reason to do that though.

···

On Aug 17, 12:34 pm, Klaas Decanniere <cphjet...@gmail.com> wrote:

Hello,

I'm fairly new to python and wxpython and the whole object-oriented
programming.
I tought I was doing fine until I ran into a problem with time.strptime()

I have attached a little test script.
I'm wondering why the first (lower) time.strptime works and the second one
gives a ValueError - do I need to something special to get this working?

This is python 2.6.5 (release26) on Gentoo linux.

Thanks for your help!

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

Thanks for the heads up.

I have done some more digging.

This test script does not work on my laptop, python 2.6.5 (GCC 4.4.3),
wxpython 2.8.10.1 on linux

It works fine on my desktop, python 2.6.5 (GCC 4.3.4), wxpython
2.8.10.1 also on linux

Some GCC downgrading might be the answer.

The test script was to try and locate the error - the Program I'm
working on parses a file upon the "File-Open" command. The parser is
in a separate module, works fine stand-alone, and uses the
time.strptime() function. When called from my (soon-to-be) GUI it
gives the ValueError message. I'm far from confident enough to know if
I'm doing something fundamentally wrong or not.

Thanks again,

Klaas

···

On Aug 17, 8:40 pm, Mike Driscoll <kyoso...@gmail.com> wrote:

On Aug 17, 12:34 pm, Klaas Decanniere <cphjet...@gmail.com> wrote:

> Hello,

> I'm fairly new to python and wxpython and the whole object-oriented
> programming.
> I tought I was doing fine until I ran into a problem with time.strptime()

> I have attached a little test script.
> I'm wondering why the first (lower) time.strptime works and the second one
> gives a ValueError - do I need to something special to get this working?

> This is python 2.6.5 (release26) on Gentoo linux.

> Thanks for your help!

This works just fine on Windows XP, wxPython 2.8.10.1, Python 2.5.
Personally, I don't see any reason to do that though.

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

IIRC time.strptime is a thin wrapper around the system's standard C library function of the same name, and that is affected by locale settings. It's possible that when the GTK lib is being initialized by wxGTK that is it (re)setting the locale in such a way that strptime is no longer able to parse the string, for example if the locale's spelling of the 5th month is not "May".

···

On 8/17/10 10:34 AM, Klaas Decanniere wrote:

Hello,

I'm fairly new to python and wxpython and the whole object-oriented
programming.
I tought I was doing fine until I ran into a problem with time.strptime()

I have attached a little test script.
I'm wondering why the first (lower) time.strptime works and the second
one gives a ValueError - do I need to something special to get this working?

This is python 2.6.5 (release26) on Gentoo linux.

--
Robin Dunn
Software Craftsman

IIRC time.strptime is a thin wrapper around the system's standard C
library function of the same name, and that is affected by locale
settings. It's possible that when the GTK lib is being initialized by
wxGTK that is it (re)setting the locale in such a way that strptime is
no longer able to parse the string, for example if the locale's spelling
of the 5th month is not "May".

That might be it. I have been creative with locale-settings to get
Openoffice csv output compatible with what our robot needs.
Is there a way to force settings in some way or do I need to change
locale settings every time?

Thanks again,

Klaas

You could probably do it by resetting the locale in your program either by creating and holding a reference to a wx.Locale object, or using the Python locale module. OTOH, if the only thing that is affected by this is the parsing of the date/time and if they are always the same format then doing your own parser would be simple and you could leave the locale set to the default.

···

On 8/17/10 1:23 PM, CPH wrote:

IIRC time.strptime is a thin wrapper around the system's standard C
library function of the same name, and that is affected by locale
settings. It's possible that when the GTK lib is being initialized by
wxGTK that is it (re)setting the locale in such a way that strptime is
no longer able to parse the string, for example if the locale's spelling
of the 5th month is not "May".

That might be it. I have been creative with locale-settings to get
Openoffice csv output compatible with what our robot needs.
Is there a way to force settings in some way or do I need to change
locale settings every time?

--
Robin Dunn
Software Craftsman