mx.DateTime.Parser.DateFromString('crap')

Sibylle Koczian Sibylle.Koczian at Bibliothek.Uni-Augsburg.de
Mon Jul 14 14:21:45 EDT 2003


David Bolen <db3l at fitlinxx.com> wrote in message news:<uznjmqtmu.fsf at fitlinxx.com>...
> Koczian <Sibylle.Koczian at Bibliothek.Uni-Augsburg.de> 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.

Koczian




More information about the Python-list mailing list