There are two problems here, one of which is an urgent problem, the other confuses you, but it is not an urgent problem. At first:
Your string is a byte object, i.e. a string of 8-bit bytes. Python 3 treats this differently than text, which is Unicode. Where did you get the line? Since you want to treat it as text, you should probably convert it to a str object that is used to process the text. This is usually done using the .decode () function, that is:
somestring.decode('UTF-8')
Although calling str () also works:
str(somestring, 'UTF8')
(Please note that your decoding may be something other than UTF8)
However, this is not your real question. Your actual question is how to remove the byte string. And asnwer is that you do it the same way you do a text string:
somestring.strip()
In Python 2 or Python, there is no built-in strip () function. In the line module in Python 2, there is a strip function:
from string import strip
But this was not good practice, since the strings got the strip () method, which now looks like ten years or so. So in Python 3 he left.
source share