String Problem, What is it I don't understand?

Terry Hancock hancock at
Fri Jan 17 11:44:58 CET 2003

Peter Hansen wrote:
> Burkhard posted the one answer, so I'm just going to point out
> that a much simpler approach for this particular problem is
> to use "split", as in
>  month, day, year = xxx.split('/')
> Unless you have to deal with dates in which the separator
> can be one of a number of options (ugh) this is much more
> readable, probably faster (not that it matters), and
> would handle four-digit years quite nicely as well.

Actually the alternate separator case is not difficult either:

import re
xxx = '1/15-2003'
month, day, year = re.split(r'[/-]', xxx)

Note also that 4 or 1 digit entries don't cause me any trouble, either.  


Anansi Spaceworks

More information about the Python-list mailing list