[Python-Dev] Python strptime

Brett Cannon bac@OCF.Berkeley.EDU
Mon, 17 Jun 2002 15:27:23 -0700 (PDT)

On 17 Jun 2002, Martin v. Loewis wrote:

> Brett Cannon <bac@OCF.Berkeley.EDU> writes:
> > Do you just want a callout to strptime or should I also include my helper
> > classes and functions?  I have implemented a class that figures out and
> > stores all locale-specific date info (weekday names, month names, etc.).
> That sounds terrible. How do you do that, and on what systems does it
> work? Do we really want to do that? Does it always work?

Well, since locale info is not directly accessible for time-specific
things in Python (let alone in C in a standard way), I have to do multiple
calls to strftime to get the names of the weekdays.  As for the strings
representing locale-specifc date, time, and date/time representation I
have to go through and figure out what the format of the output to extract
the format string used by strftime to create the string. Since it is in
pure Python and relies only on strftime and locale for its info, it works
on all systems.  I have yet to have anyone say it doesn't work for them.

As for whether that is the best solution, I think it is for the situation.
Yes, I could roll all of this into strptime itself and make it a single
monolithic function.  The reason I did this was so that the object (names
LocaleTime) could handle lazy evaluation for that info.  That way you are
not paying the price of having to recalculate the same information
thousands of times (for instance if you are parsing a huge logfile).

I also think it is helpful to have that info available separately from
strptime since locale does not provide it.

Since the locale information is not accessible any other way that I can
come up with, the only other solution is to have someone enter all the
locale-specific info by hand.  I personally would rather put up with a
more complicated strptime setup then have to worry about entering all of
that info.

-Brett C.