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

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -