import os
mypath = '/home/sb/bioinfo/test/'
pathout = 'out.fas'
fout = open(pathout,"w")
for x in os.listdir(mypath):
    fh = open(mypath+x)
    data = fh.read()
    fh.close()
    fout.write(data)
fout.close()

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