python skipping lines?
python.list at tim.thechases.com
Mon Nov 27 20:27:08 CET 2006
I'm not sure if this will /solve/ your problem, but it's
something I noticed...
> UnitList = open('/Python25/working/FacList.txt', 'r')
> RawData = open('/Python25/working/data.txt', 'r')
Here, you open RawData once...
> Output = open('/Python25/working/output.txt', 'a')
> def PullHourlyData(filename, facility, unit):
> for line in filename:
> counter = 0
> for combos in UnitList:
> PullHourlyData(RawData, FacilityName, UnitName)
> counter += 1
and your first pass through this loop, you exhaust RawData by
reading to the end. The second pass through the UnitList loop,
you pass the exhausted RawData to PullHourlyData(). I'm thinking
you'd need to RawData.seek(0) or some such "rewind" ability. A
slightly ugly alternative would be just opening/closing the
RawData file for each pass through the loop. Another, possibly
cleaner option (depending on the size of RawData's contents)
would be to just read the whole thing into an in-memory list with
data = RawData.readlines()
and then just pass "data" to PullHourlyData() each time...no need
to rewind (like VHS vs. DVD :)
Part of the confusion stems from the fact that what you refer to
as "filename" (sounds like it should be a string containing the
path to the file) is actually a file object that contains state.
More information about the Python-list