I have two files: The first file is a .txt file that contains 3 columns but i am making use of column 2 and 3. The second file is a .fasta file that contain the sequences.
Using python, I want to make each column 3 the file name and based on it compare the IDs in file1 and file2 and then use Biopython to write the sequences to the file I made(column 3)

Linearize your fasta from multi-line to single-line. I almost always do this to make parsing easier. This is my proposed solution, from what I understood from your question.

#!/usr/bin/env python
from collections import defaultdict
#open file1, using col3 as ids and col2 appending to defaultdict values
with open('file_1.txt', 'r') as f:
ids = defaultdict(list)
for line in f:
ids[line.strip().split('\t')[1]].append(line.strip().split('\t')[2])
# open file2 fasta, put sequences into dictionary with col2 ids as keys
with open('file_2.fasta', 'r') as fasta:
seqs = {}
for line in fasta:
if line.startswith('>'):
seqs[line.strip().split('|')[1]] = next(fasta).strip()
# for each id (used as new filename), print out matching col2 ids and sequences to new file
for i in ids:
with open(i + '.fasta', 'w') as out:
for n in range(len(ids[i])):
out.write('>' + ids[i][n] + '\n' + seqs[ids[i][n]])

Thanks for your response, but your code doesn't work for me. it gives a KeyError message. can you please explain a little bit the last part of the code?
When I printed out the "seqs" part, I found out that the sequences were not complete, is it something you can solve? Please can you use biopython to write to the file?