Python readline() from a string?

后端 未结 5 1407
予麋鹿
予麋鹿 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:52

    in Python string have method splitlines

    msg = "Bob Smith\nJane Doe\nJane,\nPlease order more widgets\nThanks,\nBob\n"
    msg_splitlines = msg.splitlines()
    headerTo = msg_splitlines[0]
    headerFrom= msg_splitlines[1]
    sendMessage(headerTo,headerFrom,msg)
    

提交回复
热议问题