How do you go through a text file and print the next number in python? : <p>How do you go through a text file and print the next ascending number with other information (already able to do this)? </p>

<p>For my code I need to assign a number to something the user inputs and so far I am able to do everything but get the number to print onto the text file. I would like my file to be formatted in the following way:</p>

<p><em>1    abcd</em></p>

<p><em>2    efgh</em></p>

<p>I need the code to go through the text file and see what the highest number is then print the next number with the information. Like I said before I'm having no trouble with the information part just the part on adding the numbers.</p>

<p>I have thought about doing an <em>if</em> statement however that would mean going through a lot of numbers and sooner or later it will need updating with more numbers. As well as this, it would be very time consuming as well as memory consuming.</p>

<p>I have also thought about using a <em>for</em> statement however I haven't been able to find a way of it working.</p>

<p>Any help would be greatly appreciated. Thanks</p>
