import os
while True:
    iname = raw_input("Enter input filename: ")
    oname = raw_input("Enter output filename: ")
    if os.path.exists(iname):
        fh = open(iname)
        line = fh.readline()
        fh.close()
        if "\t" in line:
            value = line.split('\t')[0]
            if os.access("/home/sb/"+oname,os.W_OK)==0:
                fw = open("/home/sb/"+oname,"w")
                if value.isdigit():
                    fw.write(str(int(value)*.2))
                    fw.close()
                    break
                else:
                    print("It can't be converted to int")
            else:
                print("Output file is not writable")
        else:
            print("There is no TAB. Check the input file")
    else:
        print("The file doesn't exist")

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