split byte string into lines

后端 未结 3 1291
离开以前
离开以前 2021-01-07 16:15

How can I split a byte string into a list of lines?

In python 2 I had:

rest = \"some\\nlines\"
for line in rest.split(\"\\n\"):
    print line
         


        
3条回答
  •  耶瑟儿~
    2021-01-07 16:27

    try this.. .

    rest = b"some\nlines"
    rest=rest.decode("utf-8")

    then you can do rest.split("\n")

提交回复
热议问题