Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-19 Thread Mark Tolonen
Gilles Ganault nos...@nospam.com wrote in message news:rtqk859vm3rkdfor0gd2u2pq5sftl8m...@4ax.com... I find it odd that the regex library can't handle European characters It can. Read the documentation about the re.LOCALE flag. -Mark -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-18 Thread Gilles Ganault
Thanks everyone for the help. This script is just a one-shot thingie on my work host, not as a web script or anything professional. On Mon, 17 Aug 2009 17:05:28 -0700 (PDT), Jonathan Gardner jgard...@jonathangardner.net wrote: Unfortunately, there isn't any string to date parsers in the built-

Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-18 Thread Ben Finney
Gilles Ganault nos...@nospam.com writes: Thanks everyone for the help. This script is just a one-shot thingie on my work host, not as a web script or anything professional. On Mon, 17 Aug 2009 17:05:28 -0700 (PDT), Jonathan Gardner jgard...@jonathangardner.net wrote:

Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-18 Thread Gilles Ganault
On Tue, 18 Aug 2009 17:10:50 +1000, Ben Finney ben+pyt...@benfinney.id.au wrote: Luckily, you have access to the documentation to find out. I never used groups before. Thanks for showing me. At this point, the script is almost done, but the regex fails if the month contains accented characters

Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-18 Thread Rami Chowdhury
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')) Since this is for a one-shot

Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-18 Thread Gilles Ganault
On Tue, 18 Aug 2009 01:11:20 -0700, Rami Chowdhury rami.chowdh...@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:

Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-18 Thread Rami Chowdhury
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

Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-18 Thread Gilles Ganault
On Tue, 18 Aug 2009 10:52:41 +0200, Gilles Ganault nos...@nospam.com wrote: I find it odd that the regex library can't handle European characters :-/ Ha, found it! :-) http://www.regular-expressions.info/python.html = # -*- coding: latin-1 -*- import locale import re

Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-18 Thread Ben Finney
Gilles Ganault nos...@nospam.com writes: dateinscription = 11 Août 2008 For any text string that's not ASCII, you should specify it as Unicode. (Actually, you should specify text as Unicode anyway.) For a literal text string: dateinscription = u11 Août 2008 If you're using exclusively

Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-18 Thread Gilles Ganault
On Tue, 18 Aug 2009 20:03:47 +1000, Ben Finney ben+pyt...@benfinney.id.au wrote: The principles of handling text in Python: Get it to internal Unicode objects as soon as possible, handle it as Unicode for as long as possible, and only encode it to some byte stream for output as late as possible.

Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-18 Thread Ben Finney
Gilles Ganault nos...@nospam.com writes: On Tue, 18 Aug 2009 20:03:47 +1000, Ben Finney ben+pyt...@benfinney.id.au wrote: The principles of handling text in Python: Get it to internal Unicode objects as soon as possible, handle it as Unicode for as long as possible, and only encode it to

Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-18 Thread Stefan Behnel
Ben Finney wrote: The principles of handling text in Python: Get it to internal Unicode objects as soon as possible, handle it as Unicode for as long as possible, and only encode it to some byte stream for output as late as possible. Again, note that these recommendations hold for *any* text

Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Gilles Ganault
Hello, I need to convert DD MM dates into the MySQL-friendly -MM-DD, and translate the month name from literal French to its numeric equivalent (eg. Janvier into 01). Here's an example: SELECT dateinscription, dateconnexion FROM membres LIMIT 1; 26 Mai 2007|17 Août 2009 - 09h20

Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Jonathan Gardner
On Aug 17, 3:26 pm, Gilles Ganault nos...@nospam.com wrote: Hello,         I need to convert DD MM dates into the MySQL-friendly -MM-DD, and translate the month name from literal French to its numeric equivalent (eg. Janvier into 01). Here's an example: SELECT dateinscription,

Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Che M
On Aug 17, 6:26 pm, Gilles Ganault nos...@nospam.com wrote: Hello,         I need to convert DD MM dates into the MySQL-friendly -MM-DD, and translate the month name from literal French to its numeric equivalent (eg. Janvier into 01). Here's an example: SELECT dateinscription,

Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Jonathan Gardner
On Aug 17, 3:26 pm, Gilles Ganault nos...@nospam.com wrote:         I need to convert DD MM dates into the MySQL-friendly -MM-DD, and translate the month name from literal French to its numeric equivalent (eg. Janvier into 01). Here's an example: SELECT dateinscription,

Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Rami Chowdhury
Correct me if I'm wrong, but doesn't http://docs.python.org/library/datetime.html#datetime.datetime.strptime do this? import locale locale.setlocale(locale.LC_ALL, 'FR') 'French_France.1252' date_str = '05 Mai 2009 - 18h25' fmt = '%d %B %Y - %Hh%M' date_obj = datetime.strptime(date_str,

Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Ben Finney
Gilles Ganault nos...@nospam.com writes: I need to convert DD MM dates into the MySQL-friendly -MM-DD This is not specific to MySQL. It is the common international standard date representation format defined by ISO 8601. and translate the month name from literal French to its

Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Ben Finney
Jonathan Gardner jgard...@jonathangardner.net writes: Unfortunately, there isn't any string to date parsers in the built- ins. Fortunately, Python 2.5 or later has the ‘datetime.strptime’ function. -- \ “You could augment an earwig to the point where it understood | `\ nuclear

Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Jonathan Gardner
On Aug 17, 5:20 pm, Ben Finney ben+pyt...@benfinney.id.au wrote: Instead, you should generate the map based on the standard library (in this case, the underlying C standard library) locale database URL:http://docs.python.org/library/locale.html?highlight=locale%20date#lo...: Does Windows

Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Jonathan Gardner
On Aug 17, 7:06 pm, Ben Finney ben+pyt...@benfinney.id.au wrote: Jonathan Gardner jgard...@jonathangardner.net writes: Unfortunately, there isn't any string to date parsers in the built- ins. Fortunately, Python 2.5 or later has the ‘datetime.strptime’ function. Hate to weasel out of this

Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Jonathan Gardner
On Aug 17, 5:18 pm, Rami Chowdhury rami.chowdh...@gmail.com wrote: import locale locale.setlocale(locale.LC_ALL, 'FR') locale is nice when you only have a single thread. Webservers aren't single threaded. You can't serve up one page for one locale and then another in another locale without

Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Ben Finney
Jonathan Gardner jgard...@jonathangardner.net writes: On Aug 17, 5:20 pm, Ben Finney ben+pyt...@benfinney.id.au wrote: Instead, you should generate the map based on the standard library (in this case, the underlying C standard library) locale database

Re: Converting DD MM YYYY into YYYY-MM-DD?

2009-08-17 Thread Rami Chowdhury
My sample interactive session (locale.setlocale and all) was on a 32-bit Vista install of Python 2.5, so it works on that... --- Rami Chowdhury A man with a watch knows what time it is. A man with two watches is never sure. -- Segal's Law 408-597-7068 (US) / 07875-841-046 (UK) /