0

I am having trouble splitting a string into lines. I receive a string that seems to be defined as

txt = str(b"line1 \n line2")

Which, as described here is transformed into the informal representation of the string.

It's like I am receiving a script defined as

txt = "b'line1 \n line2'"

How can I transform my data into

txt = "line1 \n line2"

Without doing something as ugly as

txt = txt[2:-1]

EDIT: Saw marked as duplicate but the other question does not seem to apply:

txt = str(b"line1\nline2")                                                                     
txt.decode('ascii')                                                                            
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-89-0ccdab40ee23> in <module>
----> 1 txt.decode('ascii')

AttributeError: 'str' object has no attribute 'decode'
Be Chiller Too
  • 2,502
  • 2
  • 16
  • 42

0 Answers0