Q: finding distance between 2 time's
sjmachin at lexicon.net
Sun May 31 02:49:39 CEST 2009
On May 31, 7:37 am, jkv <j... at unixcluster.dk> wrote:
> mar... at 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 a if
> (and thanks to Steven for the <= reminder)
> if os.path.isfile(x):
> nSize = os.path.getsize(x)
> #if oneliner
> if time.mktime(time.localtime()) -
> time.mktime(time.localtime(os.path.getmtime(x))) <= 3600:
> print ('HT fil -> %s %d @ %s') % (x, nSize, time.asctime)
There is no virtue in onelinedness if the code is unclear and/or
(1) Converting UTC time to local time and back again??
> import time
You are in a maze of twisty little functions, all alike.
So it can pay to do things a step at a time, and leave a note of your
intentions at each step.
(2) Consider grabbing the "current time" once instead of each for each
(3) asctime ... you are missing (an_argument)
import os, time, sys
listing = os.listdir(directory)
now_utc_secs = time.time()
for x in os.listdir(directory):
x = os.path.join(directory, x)
print ('dir -> %s') % x
mtime_utc_secs = os.path.getmtime(x)
if now_utc_secs - mtime_utc_secs <= 3600.0:
nSize = os.path.getsize(x)
mtime_local_tuple = time.localtime(mtime_utc_secs)
mtime_local_text = time.asctime(mtime_local_tuple)
print ('fil -> %s %d @ %s') % (x, nSize,
tstN = time.localtime()
print "Time now: %s" % time.asctime(tstN)
More information about the Python-list