I have implemented strptime in pure Python (SF patch #474274) as a drop-in replacement for the time module's version, but there is the issue of the time module being a C extension. Any chance of getting a Python module stub for time (assuming this patch is good enough to be accepted)? There is also obviously the option of doing something like a time2, but is there enough other time-manipulating Python code out there to warrant another module? It could be used for housing naivetime and any other code that does not directly stem from some ANSI C function. -Brett C.
I have implemented strptime in pure Python (SF patch #474274) as a drop-in replacement for the time module's version, but there is the issue of the time module being a C extension. Any chance of getting a Python module stub for time (assuming this patch is good enough to be accepted)?
There is also obviously the option of doing something like a time2, but is there enough other time-manipulating Python code out there to warrant another module? It could be used for housing naivetime and any other code that does not directly stem from some ANSI C function.
I think this should be done, but I have no time to review your strptime implementation. Can you submit (to the same patch item) a patch for timemodule.c that adds a callout to your Python strptime code when HAVE_STRPTIME is undefined? --Guido van Rossum (home page: http://www.python.org/~guido/)
On Mon, 17 Jun 2002, Guido van Rossum wrote:
I have implemented strptime in pure Python (SF patch #474274) as a drop-in replacement for the time module's version, but there is the issue of the time module being a C extension. Any chance of getting a Python module stub for time (assuming this patch is good enough to be accepted)?
There is also obviously the option of doing something like a time2, but is there enough other time-manipulating Python code out there to warrant another module? It could be used for housing naivetime and any other code that does not directly stem from some ANSI C function.
I think this should be done, but I have no time to review your strptime implementation. Can you submit (to the same patch item) a patch for timemodule.c that adds a callout to your Python strptime code when HAVE_STRPTIME is undefined?
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.). I subclass that for another class that creates the regexes used by strptime. I also have three functions that calculate missing data (Julian date from Gregorian date, etc.). But one does not need access to any of these things directly if one just wants to use strptime like in the time module, so they can be left out for now if you prefer.
--Guido van Rossum (home page: http://www.python.org/~guido/)
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev
-Brett C.
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.). I subclass that for another class that creates the regexes used by strptime. I also have three functions that calculate missing data (Julian date from Gregorian date, etc.).
But one does not need access to any of these things directly if one just wants to use strptime like in the time module, so they can be left out for now if you prefer.
If there's a way to get at the extra stuff by importing strptime.py, that's preferred. The time module only needs to support the classic strptime function. (But as I said I haven't seen your code, so maybe I misunderstand your question.) --Guido van Rossum (home page: http://www.python.org/~guido/)
On Mon, 17 Jun 2002, Guido van Rossum wrote:
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.). I subclass that for another class that creates the regexes used by strptime. I also have three functions that calculate missing data (Julian date from Gregorian date, etc.).
But one does not need access to any of these things directly if one just wants to use strptime like in the time module, so they can be left out for now if you prefer.
If there's a way to get at the extra stuff by importing strptime.py, that's preferred. The time module only needs to support the classic strptime function. (But as I said I haven't seen your code, so maybe I misunderstand your question.)
No, you understood it. I made all of it importable. I figured they might be useful in some other fashion so there is no munging of names or explicit leaving out in __all__ or anything. So my question is answered. Now I just need to write the patch. Might be a little while since I have never bothered to learn callouts from C to Python. Guess I now have my personal project for the week. -Brett C.
Brett Cannon
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? Regards, Martin
On 17 Jun 2002, Martin v. Loewis wrote:
Brett Cannon
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.
Brett,
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. [...] I also think it is helpful to have that info available separately from strptime since locale does not provide it.
What kind of information are you looking for exactly? I'm not sure if this is available in every paltform (it's standarized only by the "Single UNIX Specification" acording to my man page), but depending on this issue, everything you're looking for is there:
locale.nl_langinfo(locale.D_FMT) '%m/%d/%y'
You could also try loading a translation catalog in the target system, but that could be unportable as well. -- Gustavo Niemeyer [ 2AAC 7928 0FBF 0299 5EB5 60E2 2253 B29A 6664 3A0C ]
What kind of information are you looking for exactly? I'm not sure if this is available in every paltform (it's standarized only by the "Single UNIX Specification" acording to my man page), but depending on this issue, everything you're looking for is there:
locale.nl_langinfo(locale.D_FMT) '%m/%d/%y'
You could also try loading a translation catalog in the target system, but that could be unportable as well.
That is the type of info I am looking for, but it is not portable. Windows does not have this functionality to my knowledge. If it did it is stupid that it does not have strptime built-in. ANSI C, unfortunately, does not provide a way to get this info directly. This is why I have to get it from strftime. -Brett C.
-- Gustavo Niemeyer
That is the type of info I am looking for, but it is not portable. Windows does not have this functionality to my knowledge. If it did it is stupid that it does not have strptime built-in. ANSI C, unfortunately, does not provide a way to get this info directly. This is why I have to get it from strftime.
Well, providing strftime and not strptime is stupid already, following your point of view. :-) -- Gustavo Niemeyer [ 2AAC 7928 0FBF 0299 5EB5 60E2 2253 B29A 6664 3A0C ]
On Mon, 17 Jun 2002, Gustavo Niemeyer wrote:
That is the type of info I am looking for, but it is not portable. Windows does not have this functionality to my knowledge. If it did it is stupid that it does not have strptime built-in. ANSI C, unfortunately, does not provide a way to get this info directly. This is why I have to get it from strftime.
Well, providing strftime and not strptime is stupid already, following your point of view. :-)
Yeah. =) Since it is just reversed it is not that difficult once you have the locale information. The most difficult part of this whole module was trying to come up with a way to get that information.
-- Gustavo Niemeyer
-Brett C.
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.
I guess so -- the calendar module does the same (and then makes them available). --Guido van Rossum (home page: http://www.python.org/~guido/)
On Mon, 17 Jun 2002, Guido van Rossum wrote:
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.
I guess so -- the calendar module does the same (and then makes them available).
Perhaps this info is important enough to not be in time but in locale? I could rework my code that figures out the date info to fit more into locale. Maybe have some constants (like A_WEEKDAY, F_WEEKDAY, etc.) that could be passed to a function that would return a list of the requested names? Or could stay with the way I currently have it and just have a class that stores all of that info and has named attributes to return the info?
--Guido van Rossum (home page: http://www.python.org/~guido/)
-Brett C.
Perhaps this info is important enough to not be in time but in locale?
Perhaps, if Martin von Loewis agrees.
I could rework my code that figures out the date info to fit more into locale. Maybe have some constants (like A_WEEKDAY, F_WEEKDAY, etc.) that could be passed to a function that would return a list of the requested names? Or could stay with the way I currently have it and just have a class that stores all of that info and has named attributes to return the info?
I haven't seen your code and have no time to review it until I'm back from vacation, so can't comment on this bit. :-( --Guido van Rossum (home page: http://www.python.org/~guido/)
Brett Cannon
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.
I wonder what the purpose of having a pure-Python implementation of strptime is, if you have to rely on strftime. Is this for Windows only? Regards, Martin
On 18 Jun 2002, Martin v. Loewis wrote:
Brett Cannon
writes: 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.
I wonder what the purpose of having a pure-Python implementation of strptime is, if you have to rely on strftime. Is this for Windows only?
The purpose is that strptime is not common across all platforms. As it stands now, it requires that the underlying C library support it. Since it is not specified in ANSI C, not all have it. glibc has it so most UNIX installs have it. But Windows doesn't. It is not meant specifically for Windows, but it happens to be the major OS that lacks it. But strftime is guaranteed by Python to be there since it is in ANSI C. The reason I have the reliance on strftime is because it was the only way I could think of to reliably gain access to locale information in regards for time. If I didn't try to figure out what the names of months were, I would not need strftime at all. But since I wanted this to be able to be a drop-in replacement, I decided it was worth my time to figure out how to get this locale info when it is not directly accessible. As for why it is in Python and not C, it's mainly because I prefer Python. =) I think it could be done in C, but it would be much more work. I also remember Guido saying somewhere that he would like to see modules in Python when possible. It was possible, so I did it in Python.
Regards, Martin
-Brett C.
Hi, Brett Cannon: [...]
The purpose is that strptime is not common across all platforms. As it stands now, it requires that the underlying C library support it. Since it is not specified in ANSI C, not all have it. glibc has it so most UNIX installs have it. But Windows doesn't. It is not meant specifically for Windows, but it happens to be the major OS that lacks it. [...]
There is some relationship betweeen the time module and the calendar module, which is also a long time member of the Python standard library. If your new code becomes part of the standard library, please have a look at the calendar module and its documentation. At least crossreferencing pointers should be added. May be someone will come up with a "locale-awareness" patch to calendar? Currently month and weekday names are constants hardcoded in english in calendar.py. The stuff you wrote might help here. Regards, Peter -- Peter Funk, Oldenburger Str.86, D-27777 Ganderkesee, Germany, Fax:+49 4222950260 office: +49 421 20419-0 (ArtCom GmbH, Grazer Str.8, D-28359 Bremen, Germany)
Currently month and weekday names are constants hardcoded in english in calendar.py.
No they're not. You're a year behind. ;-) --Guido van Rossum (home page: http://www.python.org/~guido/)
On Tue, 18 Jun 2002, Guido van Rossum wrote:
Currently month and weekday names are constants hardcoded in english in calendar.py.
No they're not. You're a year behind. ;-)
Didn't realize that; undocumented feature. I will change my code to use calendar for getting the names of the days of the week and months. I still have my code, though, that figures out the format strings for date, time, and date/time if Martin wants to use that in locale.
--Guido van Rossum (home page: http://www.python.org/~guido/)
-Brett C.
Guido van Rossum:
Currently month and weekday names are constants hardcoded in english in calendar.py.
No they're not. You're a year behind. ;-)
Oupppsss! Sorry. I must admit I looked at the most recent documentation and not at the most recent source code and so I missed the clever patch written by Denis S. Otkidach. Obviously there are still some more \versionchanged{} missing in python/dist/src/Doc/lib/libcalendar.tex. I will see, if I can provide another doc patch. Regards, Peter -- Peter Funk, Oldenburger Str.86, D-27777 Ganderkesee, Germany, Fax:+49 4222950260 office: +49 421 20419-0 (ArtCom GmbH, Grazer Str.8, D-28359 Bremen, Germany)
I wonder what the purpose of having a pure-Python implementation of strptime is, if you have to rely on strftime. Is this for Windows only?
Isn't the problem that strftime() is in the C standard but strptime() is not? So strptime() isn't always provided but we can count on strftime()? --Guido van Rossum (home page: http://www.python.org/~guido/)
On Tue, 18 Jun 2002, Guido van Rossum wrote:
I wonder what the purpose of having a pure-Python implementation of strptime is, if you have to rely on strftime. Is this for Windows only?
Isn't the problem that strftime() is in the C standard but strptime() is not? So strptime() isn't always provided but we can count on strftime()?
Exactly. For some reason ANSI decided to go to the trouble of requiring strftime(), and thus all of the locale info for it, but not strptime() nor a standard way to expose that locale info for the programmer to use.
--Guido van Rossum (home page: http://www.python.org/~guido/)
-Brett C.
On Tuesday, June 18, 2002, at 07:30 , Martin v. Loewis wrote:
I wonder what the purpose of having a pure-Python implementation of strptime is, if you have to rely on strftime. Is this for Windows only?
MacPython would benefit as well: it also has strftime() but not
strptime(). There's currently a pure-python implementation of strptime()
in the Contrib folder, but Brett's solution would better (the Contrib
strptime can't be incorporated because it's under GPL license, and the
automatic callout to Python would be really nice as it makes this
user-invisible).
--
- Jack Jansen
Brett, Have you looked at calendar.py? It already does locale-specific weekday and month names. Localizing that code into a single place seems like it would be a good idea? Skip
Guido> Can you submit (to the same patch item) a patch for timemodule.c Guido> that adds a callout to your Python strptime code when Guido> HAVE_STRPTIME is undefined? I thought the preferred way to do this would be to implement a Lib/time.py module that includes Brett's strptime() function, move Modules/timemodule.c to Modules/_timemodule.c and at the end of Lib/time.py import the symbols from _time. Skip
participants (8)
-
Brett Cannon
-
Fredrik Lundh
-
Guido van Rossum
-
Gustavo Niemeyer
-
Jack Jansen
-
martin@v.loewis.de
-
pf@artcom-gmbh.de
-
Skip Montanaro