Re: python skipping lines?



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:
[cut]
counter = 0

for combos in UnitList:
[cut]
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 something like

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.

-tkc




.



Relevant Pages

  • filenames with spaces and list in a for loop
    ... Second attempt was to double quote the "`ls -1A $1`", which generates ONE huge argument to the for loop. ... Unfortunately, the list also generates a newline every 80 characters in the $LIST, so once in a while I was left with each_item being set to something like "\nfilename". ... At the first occurrence of $each_item in the function I would get something like <filename> not found. ... what if I have a directory with more than 65000 characters worth? ...
    (comp.unix.shell)
  • Re: long running perl programs & memory untilization
    ... >> It does setup stuff, and then goes into a loop. ... # reads in temporary capture file adds timestamp, ... # Argument 1 is filename that the labled image should be stored as ... my $grab = $_; ...
    (comp.lang.perl.misc)
  • Re: DTS query result to file - can I loop it?
    ... How to loop through a global variable Rowset ... How can I change the filename for a text file connection? ... The values for @MyType are stored in a database table so a cursor ... > existing DTS package or will I have to create a new package to handle each ...
    (microsoft.public.sqlserver.dts)
  • Re: Downloading multiple files
    ... Dim fn As Variant, f As Integer, i As Integer, counter As ... Windows.Activate 'Change the filename to match ... loop, but the last digits (time stamp) are not repeatable, as the ...
    (microsoft.public.excel.programming)
  • Re: Best way to integrate all filenames in a directory with SQL Recordset?
    ... Actual filename value transform from old to new is more like Filename.1 -> ... mismatch lists if something goes wrong. ... I will see what I can do to add another loop mid-stream to catch all file ... > Your destination I can only presume has 4 attributes ...
    (microsoft.public.sqlserver.dts)