Python, if statement to change a number
<p>I am learning Python, and I made a script which searches for several lines that contain the "keyword" and then write/print in a new file the (previously) selected list-line (I used a second argument to select the line from the list).</p>

<p>Everything went well until I tried to add a statement in case my selected list-line is > than the actual len(list) then the selected list_line = len(list); for whatever reason, it does not work.</p>

<p>Can anyone please point out to why it is not working, this my script. Thanks a million for the help. (Here is <a href="https://dl.dropbox.com/u/63216126/ActCat.out" rel="nofollow">a link</a> with an example of the files that I am using as an input)</p>

<pre><code>    import sys
    import re

    filename = sys.argv[1]
    line_select = int(sys.argv[2])


    newfile = str(filename) + ".3d"

    openold = open(filename,"r")
    opennew = open(newfile,"w")

    rline = openold.readlines()

    energies = []

    line_number = 0

    for line in rline:
        line_number += 1
        if re.search( r"SCF Done", line ):
            words = line.split()
            energy = float( words[4] )
            energies.append(str(line_number) + " : " + "The energy of the molecule is %f kcal mol-1" % energy)

    len_list = len(energies)

    if line_select &gt; len_list:
        line_select = len_list

    print &gt;&gt;opennew, energies[line_select]

    openold.close()
    opennew.close()
</code></pre>
