0
別のファイルから読み込むことによって、新しいファイルに部分文字列を書き込む必要があります。私が直面している問題は、最後に見つかった部分文字列しか書いていないことです。 これは私が試みたものです。あなたがファイルを毎回再作成w
モードで内部のファイルを開いたためだ新しいファイルへのデータの読み書きPython
def get_fasta(site):
with open('file1.txt', 'r') as myfile:
data=myfile.read()
site = site-1
str1 = data[site:site+1+20]
temp = data[site-20:site]
final_sequence = temp+str1
with open('positive_results_sequences.txt', 'w') as my_new_file:
my_new_file.write(final_sequence + '\n')
def main():
# iterate over the list of IDS
for k,v in zip(site_id_list):
get_fasta(v)
if __name__ == '__main__':
main()
ありがとうございました。 – Ghauri