import os
while True:
    try:
        iname = raw_input("Enter input filename: ")
        oname = raw_input("Enter output filename: ")
        fh = open(iname)
        line = fh.readline()
        fh.close()
        value = line.split('\t')[0]
        fw = open("/home/sb/"+oname,"w")
        fw.write(str(int(value)*.2))
        fw.close()
    except IOError, (errno,errtext):
        if errno==13:
            print("Can't write to outfile.")
        elif errno==2:
            print("File not exist")
    except ValueError, strerror:
        if "substring not found" in strerror.message:
            print("There is no tab")
        elif "invalid literal for int" in strerror.message:
            print("The value can't be converted to int")
            fw.close()
    else:
        print("Thank you!. Everything went OK.")
        break

This code is part of the book "Python for Bioinformatics", by Sebastian Bassi (sbassi@genesdigitales.com). Return to home page.