<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def putout(ofile, keylist, Rec):
 """ writes out a magic format record to ofile """

    pmag_out = open(ofile, 'a')
    outstring = ""
    for key in keylist:
        try:
            outstring = outstring + '\t' + str(Rec[key]).strip()
        except:
            print(key, Rec[key])
            # raw_input()
    outstring = outstring + '\n'
    pmag_out.write(outstring[1:])
    pmag_out.close()