<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def magic_write_old(ofile, Recs, file_type):
 """ writes out a magic format list of dictionaries to ofile Parameters _________ ofile : path to output file Recs : list of dictionaries in MagIC format file_type : MagIC table type (e.g., specimens) Effects : writes a MagIC formatted file from Recs """

    if len(Recs) < 1:
        print ('nothing to write')
        return
    pmag_out = open(ofile, 'w')
    outstring = "tab \t" + file_type + "\n"
    pmag_out.write(outstring)
    keystring = ""
    keylist = []
    for key in list(Recs[0].keys()):
        keylist.append(key)
    keylist.sort()
    for key in keylist:
        keystring = keystring + '\t' + key.strip()
    keystring = keystring + '\n'
    pmag_out.write(keystring[1:])
    for Rec in Recs:
        outstring = ""
        for key in keylist:
            try:
                outstring = outstring + '\t' + str(Rec[key].strip())
            except:
                if 'er_specimen_name' in list(Rec.keys()):
                    print(Rec['er_specimen_name'])
                elif 'er_specimen_names' in list(Rec.keys()):
                    print(Rec['er_specimen_names'])
                print(key, Rec[key])
                # raw_input()
        outstring = outstring + '\n'
        pmag_out.write(outstring[1:])
    pmag_out.close()