Building Time Based Bins
Michael Spencer
mahs at telcopartners.com
Tue Mar 22 00:01:20 EST 2005
MCD wrote:
> Hi Michael, thanks for responding. I actually don't use a method to get
> each bin...
That's because you picked the wrong suggestion ;-) No, seriously, you can do it
easily with this approach:
> the bin outputs are nested in the loop. Here's my code:
> data_file = open('G:\file.txt')
> DUMMY = 9999
> bintm = DUMMY
bins = []
> for line in data_file:
> fields = line.strip().split()
> if not line: continue
> ilist = [int(time), int(a)]
(BTW, there must be more to your code than you have shared for the above line to
execute without raising an exception - where are 'time' and 'a' initially bound?
BTW2, 'time' is the name of a stdlib module, so it's bad practice to use it as
an identifier)
> # print "ilist:", ilist
> klock, a = ilist
> newbintm = ((klock + 4) // 5 * 5 ) % 2400
> print "bintm = %d, newbintm = %d, a = %d" % (bintm, newbintm, a)
> # the above is the raw data and now the bin loop
> if bintm == 9999:
> bintm = newbintm
> binlo = a
> elif bintm == newbintm:
> binlo = min(binl, t)
> else:
> print " ==>> %04d %2d" % (bintm, binl) ## this is the bin
This is where you've declared that you have a bin, so add it to the bins cache:
bins.append((bintm, binl))
> bintm = newbintm
> binl = a
>
Michael
More information about the Python-list
mailing list