How to get time.strptime for Windows
Hamish Lawson
hamish_lawson at yahoo.co.uk
Mon Jun 25 18:08:15 EDT 2001
On various occasions people who have missed having the time.strptime
function on Windows have been referred to a Python implementation by
Andy Markebo that is available at
http://www.fukt.hk-r.se/~flognat/hacks/strptime.py
After installation in a suitable place on the Python path, this is then
available as strptime.strptime. However perhaps you would like to be
able to refer to it as time.strptime (maybe you have other code that
expects to call it as such)? But there's no time.py file to cut and
paste the code from strptime.py into. We can, though, make use of the
fact that imported modules are mutable objects in Python and so make
time.strptime be an alias for strptime.strptime:
import time, strptime
time.strptime = strptime.strptime
del strptime
You can even have this aliasing done automatically by putting the above
code in a file sitecustomize.py on the Python path; the Python
interpreter automatically tries to import this module when it starts
up. Thus:
Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> from time import strptime
>>> strptime('2001-07-8', '%Y-%m-%d')
(2001, 7, 8, 0, 0, 0, 0, 0, 0)
Hamish Lawson
____________________________________________________________
Do You Yahoo!?
Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
or your free @yahoo.ie address at http://mail.yahoo.ie
More information about the Python-list
mailing list