0
我必須通過讀取另一個文件來將子字符串寫入新文件。我面臨的問題是它只寫入最後找到的子字符串。 這是我試過的。將數據讀寫到新文件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