If I have a txt file and it contains something like this:
AGCGTTGATAGTGCAGCCATTGCAAAACTTCACCCTA
AGCGTTGATAGTGCAGCCATTGCAAAACTTCACCCTA
AAGAAACGAGTATCAGTAGGATGCAGACGGTTGATTG
But there are "\n" between lines.
And now if I want to make triplets out of them. Then is there a way to read the whole txt file as a line so it wouldn't give me:
'CAA', 'TGC', '\nAG', 'CGT', 'TGA', 'TAG', 'TGC', 'AGC',
I uploaded my whole code I have at the moment because none of the given answers seemed to help.
That's the code I'm using to split the whole string into triplets:
fob = open("Exercise.txt", "r")
def read_from_file(filename):
raw_txt = filename.read()
triplets = [raw_txt[i:i+3] for i in range(0, len(raw_txt), 3)]
read_from_file(fob)