While Loop Not Performing Main Function
<p>I'm trying to write a Python script that uses a particular external application belonging to the company I work for. I can generally figure things out for myself when it comes to programming and scripting, but this time I am truely lost!</p>

<p>I can't seem to figure out why the while loop wont function as it is meant to. It doesn't give any errors which doesn't help me. It just seems to skip past the important part of the code in the centre of the loop and then goes on to increment the "count" like it should afterwards!</p>

<pre><code>f = open('C:/tmp/tmp1.txt', 'w')    #Create a tempory textfile
f.write("TEXTFILE\nTEXTFILE\nTEXTFILE\nTEXTFILE\nTEXTFILE\nTEXTFILE\n") #Put some simple text in there
f.close()   #Close the file

count = 0   #Insert the line number from the text file you want to begin with (first line starts with 0)
num_lines = sum(1 for line1 in open('C:/tmp/tmp1.txt')) #Get the number of lines from the textfile

f = open('C:/tmp/tmp2.txt', 'w')    #Create a new textfile
f.close()   #Close it

while (count &lt; num_lines):  #Keep the loop within the starting line and total number of lines from the first text file
    with open('C:/tmp/tmp1.txt', 'r') as f: #Open the first textfile
        line2 = f.readlines()   #Read these lines for later input
        for line2[count] in f:  #For each line from chosen starting line until last line from first text file,...
            with open('C:/tmp/tmp2.txt', 'a') as g: #...with the second textfile open for appending strings,...
                g.write("hello\n")  #...write 'hello\n' each time while "count" &lt; "num_lines"
    count = count + 1   #Increment the "count"
</code></pre>

<p>I think everything works up until: "for line2[count] in f:"</p>

<p>The real code I'm working on is somewhat more complicated, and the application I'm using isn't exactly for sharing, so I have simplified the code to give silly outputs instead just to fix the problem.</p>

<p>I'm not looking for alternative code, I'm just looking for a reason why the loop isn't working so I can try to fix it myself.</p>

<p>All answers will be appreciated, and thanking everyone in advance!</p>

<p>Cormac</p>
