Split a string by backslash in python

后端 未结 5 1196
悲哀的现实
悲哀的现实 2020-12-06 09:41

Simple question but I\'m struggling with it for too much time. Basically I want to split a string by \\ (backslash).

 a = \"1\\2\\3\\4\"

Tr

5条回答
  •  抹茶落季
    2020-12-06 10:11

    According to this answer:

    https://stackoverflow.com/a/2081708/3893465

    you'll need to escape the backslashes before splitting as such:

    >>> a = "1\2\3\4"
    >>> a.encode('string-escape').split("\\x")
    ['1', '02', '03', '04']
    

提交回复
热议问题