How to find largest number in file and see on which line it is
<p>The file looks like this:</p>

<pre><code>1, a b
2, c d
3, e f
</code></pre>

<p>my current code </p>

<pre><code>b = open('file.txt', 'r')

c = b.readlines()
regels = len(c)

print(regels)
</code></pre>

<p>I got the numbers of lines but still need biggest number + on which line it is. </p>

<p>This is how I'd go about doing it.</p>

<pre><code>max_num = 0
with open('file.txt', 'r') as data: # use the with context so that the file closes gracefully
  for line in data.readlines(): # read the lines as a generator to be nice to my memory
    try:
      val = int(line.split(",")[0])
    except ValueError: # just incase the text file is not formatted like your example
      val = 0
    if val &gt; max_num: # logic
      max_num = val

print max_num #result
</code></pre>

python