syntax-check with regular expressions?
alf at merlin.fayauffre.org
Thu Jul 29 12:08:08 CEST 2004
Le 27-07-2004, Duncan Booth <me at privacy.net> a écrit :
> Don't use a regexp for this sort of task, its much better to do the
> conversion and catch an error if the conversion fails. In this case you
> should use time.strptime with an appropriate format. Sample code as
Just as a side note, be careful with strptime, if you have cross
platform portability in mind. On older versions of python, this function
is not available on Windows, and on Unix systems, it relies on the C
library which is not always the GNU libc, which means that some
extensions available on linux systems are not available on Unix boxes.
We had the case on project which was deployed on AIX, and had to fight
with IBM's strptime implementation regarding white space handling. I
think it used to be picky with leading zeros too.
More information about the Python-list