Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have been trying to do a very simple task but seems pretty hard. I am trying to split a string at the backslash ('\'). I have found few similar posts to this topic but no one was actually addressing a comprehensive issue.

This is the string I want to chop up:

'13
Bono
Goalkeeper
Apr 5, 1991 (29)
€15.00m  '

The problem is if I use .split('\') with the string above I get a syntax error:

SyntaxError: EOL while scanning string literal

I have also tried:

  • Double backslash \
  • Triple quotes """\"""

But it doesn't work either.

I know I can add r in front of a string but would not be suitable as the string is part of a huge list and would have to add to each string the r in front of it.

In conclusion, is there a simple way to simply chop up words using the backslash as the delimiter?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
2.9k views
Welcome To Ask or Share your Answers For Others

1 Answer

you have to do:

'your string'.split('
')

because you don't have a backslesh '\' but a newline escape charater ' '


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...