I've got a problem with this file. When I launch it I get an error on line 24.
UnboundLocal Error : local variable 'file_out' referenced before assignment.
Any suggestion on how to correct it will be greatly appreciated. I have to say that I'm a complete noob on python and didn't write this by myself.
#!/usr/local/python
import sys, getopt
import os
usage="python correct_mol2.py -i 2qab_ligand.mol2 -o 2qab_ligand_new.mol2\n"
def main(argv):
    try:
        opts,args = getopt.getopt(sys.argv[1:],'hi:o:')
    except getopt.GetoptError:
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print usage
            sys.exit()
        elif opt == '-i':
                file_in = arg
        elif opt == '-o':
            file_out = arg
    x=0
    fout=file("%s"%file_out,"w")
    for line in file(file_in):
#       print line
        if line.find("@<TRIPOS>BOND") >= 0:
            x=0
        if x==0:
            fout.write(line)
        if x==1:
            if line[47:49] == '35' :
                fout.write(line[:47]+"Br"+line[49:])
                continue
            if line[47:49] == '17' :
                fout.write(line[:47]+"Cl"+line[49:])
                continue
            if line[47:48] == '9' :
                fout.write(line[:47]+"F"+line[48:])
                continue
            if (line[47] == 'H' and line[48] ==' ') or line[47] == 'F' or line[47:49] == 'Br' or line[47:49] == 'Cl' :
                fout.write(line)
                continue
            else:
                fout.write(line[:48]+"."+line[48:54]+line[55:])
        if line.find("@<TRIPOS>ATOM") >= 0:
            x=1
    fout.close()
main(sys.argv)