Hendrik van Rooyen
mail at microcorp.co.za
Sat Nov 3 08:20:14 CET 2007
Beema shafreen wrote:
8< ------------------- file --------------------
>fh = open('complete_span','r')
>line = fh.readline().split('#')
>old_probe = line.strip()
>old_value = line.strip()
>print old_probe, old_value
>count = 1
Better to start the count off as zero....
>line = ""
This will do nothing, because line has nothing.
start with: line = "First rubbish thing to get the while loop going"
or even better, see below
> line = fh.readline().strip()
> if line :
round about here, you should maybe increment the count.
something like : count += 1
anywhere under this true branch of the 'if line'
Do you realise that this whole "if line" can be
avoided, as the while loop will look after it if
you read the first line outside the loop at the start,
and read the next line at the end of the while, before
looping back? It is a redundant check.
> current_probe, current_value = line.split('#')[0:2]
> probe =current_probe.strip()
> value = current_value.strip()
> if int(old_value) > int(value):
> res_value='%s\t%s'%(old_value, old_probe)
> print res_value
Then you have a fighting chance that the following may work,
if you have enough lines in your file.
> if count >= 244000:
> old_probe,old_value =probe, value
HTH - Hendrik
More information about the Python-list