Sibylle Koczian Sibylle.Koczian at
Mon Jul 14 20:21:45 CEST 2003

David Bolen <db3l at> wrote in message news:<uznjmqtmu.fsf at>...
> Koczian <Sibylle.Koczian at> writes:
> Double check that you're using a recent version of the egenix base
> package (probably 2.0.3 or later).  The parser module functions such
> as DateFromString were augmented to accept an optional list of parsers
> to try, which allows you to override the default.  The default does
> include an "unknown" parser which will default to the current date as
> in prior versions, but if you exclude that you'll get a ValueError
> exception if none of the other parsers match.
> For example:
> >>> import mx.DateTime
> >>> print mx.DateTime.Parser._date_formats
>  ('euro', 'us', 'altus', 'iso', 'altiso', 'lit', 'altlit', 'eurlit', 'unknown')
> >>> print mx.DateTime.Parser.DateFromString('crap')
>  2003-07-10 00:00:00.00
> >>> myformats=mx.DateTime.Parser._date_formats[:-1]
> >>> print myformats
>  ('euro', 'us', 'altus', 'iso', 'altiso', 'lit', 'altlit', 'eurlit')
> >>> print mx.DateTime.Parser.DateFromString('crap',formats=myformats)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   <...snip...>
> ValueError: unknown date format: "crap"
Exactly. Found this out after posting, of course, except that I
overlooked the "_date_formats" and typed in everything myself.

Thank you for not pointing out that it's all in the doc ... next time
I'll look more carefully.


More information about the Python-list mailing list