syntax-check with regular expressions?

Alexandre Fayolle alf at merlin.fayauffre.org
Thu Jul 29 06:08:08 EDT 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 
> requested:

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. 

-- 
Alexandre Fayolle
Logilab



More information about the Python-list mailing list