Split string based on a regular expression

后端 未结 4 1877
我寻月下人不归
我寻月下人不归 2020-11-27 12:26

I have the output of a command in tabular form. I\'m parsing this output from a result file and storing it in a string. Each element in one row is separated by one or more w

4条回答
  •  半阙折子戏
    2020-11-27 13:05

    The str.split method will automatically remove all white space between items:

    >>> str1 = "a    b     c      d"
    >>> str1.split()
    ['a', 'b', 'c', 'd']
    

    Docs are here: http://docs.python.org/library/stdtypes.html#str.split

提交回复
热议问题