Re: Q: finding distance between 2 time's

2009-06-29 Thread Scott David Daniels
John Gordon wrote: In <023130ef$0$19421$c3e8...@news.astraweb.com> Steven D'Aprano writes: if time_difference < 3601: That's a potential off-by-one error. [...] The right test is: if time_difference <= 3600: Aren't those two comparisons the same? Only if time_difference is an integ

Re: Q: finding distance between 2 time's

2009-06-29 Thread Nobody
On Mon, 29 Jun 2009 19:15:08 +, John Gordon wrote: >> > if time_difference < 3601: > >> That's a potential off-by-one error. [...] The right test is: > >> if time_difference <= 3600: > > Aren't those two comparisons the same? Not if time_difference is a float. -- http://mail.pyth

Re: Q: finding distance between 2 time's

2009-06-29 Thread John Gordon
In <023130ef$0$19421$c3e8...@news.astraweb.com> Steven D'Aprano writes: > > if time_difference < 3601: > That's a potential off-by-one error. [...] The right test is: > if time_difference <= 3600: Aren't those two comparisons the same? -- John Gordon A is for Amy,

Re: Q: finding distance between 2 time's

2009-05-31 Thread CTO
On May 30, 8:49 pm, John Machin wrote: >   > import time >   You are in a maze of twisty little functions, all alike. Quote of the week. Perhaps the year. I hope you don't mind me using it in the future. Geremy Condra -- http://mail.python.org/mailman/listinfo/python-list

Re: Q: finding distance between 2 time's

2009-05-31 Thread Anders J. Munch
jkv wrote: Hi Martin, What i usally do is to convert the two times to seconds since epoch and compare the two values in seconds. You can use time.mktime to convert localtime to seconds since epoch. There's no need to convert - simply retrieve the times as absolute times to begin with: fil

Re: Q: finding distance between 2 time's

2009-05-31 Thread John Machin
On May 31, 10:19 pm, mar...@hvidberg.net wrote: > >http://en.wikipedia.org/wiki/Subtraction > > Only one problem, wise arse: > TypeError: unsupported operand type(s) for -: 'time.struct_time' and > 'time.struct_time' > > Like I didn't try that... The point being that you can subtract them in other

Re: Q: finding distance between 2 time's

2009-05-31 Thread martin
> > http://en.wikipedia.org/wiki/Subtraction > Only one problem, wise arse: TypeError: unsupported operand type(s) for -: 'time.struct_time' and 'time.struct_time' Like I didn't try that... -- http://mail.python.org/mailman/listinfo/python-list

Re: Q: finding distance between 2 time's

2009-05-31 Thread martin
On May 30, 11:37 pm, jkv wrote: > mar...@hvidberg.net wrote: > > Thanks both > > > The first answer is quite instuctive, the other one might be the one > > I'll use in t > > I didn't receive the other answer, could you please forward it to me?> So 2x > thanks. > > You are welcome. > > I took anot

Re: Q: finding distance between 2 time's

2009-05-31 Thread martin
On May 30, 4:10 pm, Steven D'Aprano wrote: > On Sat, 30 May 2009 12:06:55 +0200, jkv wrote: > > I added a few lines to your script, and now it ought to only print files > > newer than 3601 seconds (3600 seconds is one hour). > ... > >     #if file newer than one hour print a line > >     if time_d

Re: Q: finding distance between 2 time's

2009-05-30 Thread John Machin
On May 31, 7:37 am, jkv wrote: > mar...@hvidberg.net wrote: > > Thanks both > > > The first answer is quite instuctive, the other one might be the one > > I'll use in t > > I didn't receive the other answer, could you please forward it to me?> So 2x > thanks. > > You are welcome. > > I took anoth

Re: Q: finding distance between 2 time's

2009-05-30 Thread John Machin
On May 30, 7:33 pm, mar...@hvidberg.net wrote: > I made this little script (below) to look througt a dir to see if > there are any files newer than .e.g. 1 hour. > I have the loop through the dir working and can retreive file time as > well as present time. > both time variables are in the format r

Re: Q: finding distance between 2 time's

2009-05-30 Thread jkv
mar...@hvidberg.net wrote: > Thanks both > > The first answer is quite instuctive, the other one might be the one > I'll use in t I didn't receive the other answer, could you please forward it to me? > So 2x thanks. You are welcome. I took another look at your code, and you can compress it all to

Re: Q: finding distance between 2 time's

2009-05-30 Thread Steven D'Aprano
On Sat, 30 May 2009 12:06:55 +0200, jkv wrote: > I added a few lines to your script, and now it ought to only print files > newer than 3601 seconds (3600 seconds is one hour). ... > #if file newer than one hour print a line > if time_difference < 3601: That's a potential off-by-one erro

Re: Q: finding distance between 2 time's

2009-05-30 Thread martin
Thanks both The first answer is quite instuctive, the other one might be the one I'll use in the code, it's nicely compact and clear. So 2x thanks. :-) Martin -- http://mail.python.org/mailman/listinfo/python-list

Re: Q: finding distance between 2 time's

2009-05-30 Thread jkv
Hi Martin, What i usally do is to convert the two times to seconds since epoch and compare the two values in seconds. You can use time.mktime to convert localtime to seconds since epoch. I added a few lines to your script, and now it ought to only print files newer than 3601 seconds (3600 seconds

Q: finding distance between 2 time's

2009-05-30 Thread martin
I made this little script (below) to look througt a dir to see if there are any files newer than .e.g. 1 hour. I have the loop through the dir working and can retreive file time as well as present time. both time variables are in the format returned by time.localtime() My question: How do I find t