python - Read all files from folder and edit -
i trying read fasta files test folder , put name of file in headers of individual file. code working first file , dont proceed second file , return error. me find bug in code or edit it. thanks
import sys, glob, os, string header = '' check = 0 path = "./test/" dirs = os.listdir(path) file in dirs: fp = open(file, "r") fpx = open('%s_output.txt' % file, 'w') line in fp: if line.startswith('>'): line = line.rstrip() check = check + 1 if check >= 1: header = line fpx.write(header + '_' + file + '\n') else: line = line.rstrip() fpx.write(line + '\n')
it provide error message getting! think must fail "file not found" because try open file name instead of path. try fp = open(os.path.join(path, file), "r")
:
import sys, glob, os, string header = '' check = 0 path = "./test/" dirs = os.listdir(path) file in dirs: fp = open(os.path.join(path, file), "r") fpx = open('%s_output.txt' % file, 'w') line in fp: if line.startswith('>'): line = line.rstrip() check = check + 1 if check >= 1: header = line fpx.write(header + '_' + file + '\n') else: line = line.rstrip() fpx.write(line + '\n')
Comments
Post a Comment