[Newbie] Need help with quick text proggy.

Sean 'Shaleh' Perry shalehperry at attbi.com
Wed Oct 9 23:53:52 EDT 2002


On Wednesday 09 October 2002 19:55, Corey Woodworth wrote:
> I havn't programmed in python in a while (not since 2.0) but I just
> found myself in a predicament where I really need to write a program
> and write it fast. Python still seems to be the best choice even
> though I'm very rusty and wasn't to good to start with. Here is my
> problem. I've got a text file that is a list of elements. a time
> followed by a number on each line. Like this for example:
>
> 1:46p	65
> 5:45a	99
> 2:36p	88
> 10:53a	79
> 5:10a	86
> 2:43p	169
> 10:14a	55
>
> I just found out that all my times are 6 hours off. (AARGH!) and I
> need some help writing a program that will update all those timestamps
> for me. Any help at all is appreciated, wheter it be links, some
> source, or whatever. Thank a bunch.
>
> Corey

>>> from mx import DateTime
>>> DateTime.strptime("1:46pm", "%R%p") + DateTime.TimeDelta(hours=6)
<DateTime object for '0001-01-01 07:46:00.00' at 812c130>

You just need to convert the 'a' and 'p' to 'am' and 'pm' before using the 
DateTime code.

This is not standard python, but it is on the vaults and I just did 'apt-get 
install python2.2-egenix-mxdatetime' on my Debian box.




More information about the Python-list mailing list