'Appending string to list adds a '\r' to every element
I am trying to append a string to a list (seqs). The strings look something like random letters which I am reading line by line from a file. Printing out the string shows no sign of a '\r'. But printing out the list does.
seqs.append(seq)
print('seq is', seq)
gives: seq is CSMKMTIGSGTKTLHRWAFNPTQQTCVTFVYTGAAGNQNNFLTRNDCVNTC
print(seqs)
gives: 'CSMKMTIGSGTKTLHRWAFNPTQQTCVTFVYTGAAGNQNNFLTRNDCVNTC\r'
I have tried changing the file a few different ways, even writing an example file of just lines of text so I am fairly certain I am not adding a '\r' to the file. Any help would be much appreciated.
Edit: I printed the sequence differently and I do see the carriage return now. Is there anyway I can remove it? For now when I parse through the sequences I just say if it's '\r' continue. To skip it
It's reading a gzip file and opening it with:
with gzip.open(filepath, 'rb') as fin:
file_content = fin.read().decode(encoding)
lines = file_content.split('\n')
for line in lines: #separate them into a list
EDIT EDIT I just did file_content.split('\r\n')...Seemed to fix the problem, not sure why I did not think of it sooner. Thanks everyone!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
