Python readline() from a string?

后端 未结 5 1413
予麋鹿
予麋鹿 2020-12-23 20:21

In python, is there a built-in way to do a readline() on string? I have a large chunk of data and want to strip off just the first couple lines w/o doing split() on the who

5条回答
  •  太阳男子
    2020-12-23 20:39

    The easiest way for both python 2 and 3 is using string's method splitlines(). This returns a list of lines.

    >>> "some\nmultilene\nstring\n".splitlines()
    

    ['some', 'multilene', 'string']

提交回复
热议问题