Extract sequences from MultiFASTA aligned file, by coordinates
You can use SeqIO for the writing in addition to reading the sequences. This has the advantage that it will always write the correct fasta header, which is not always just the .id if there is whitespace, e.g. (untested)
from Bio import SeqIO

with open(&quot;Spike protein.fasta&quot;, &quot;w&quot;) as out:
    for seq_record in SeqIO.parse(&quot;Whole genome.fas&quot;, &quot;fasta&quot;):
        seq_record.seq = seq_record.seq[21563:25384]
        SeqIO.write(seq_record, out, &quot;fasta&quot;)

BTW don't put spaces in your filenames, it can lead to issues