How can I remove the first line of a multi-line string?

Steven D'Aprano steve at pearwood.info
Wed Dec 16 05:18:35 EST 2015


On Wed, 16 Dec 2015 11:42 am, sgardne at gmail.com wrote:

> On Monday, September 2, 2013 at 11:53:32 AM UTC-5, MRAB wrote:
>> On 02/09/2013 17:12, Chris "Kwpolska" Warrick wrote:
>> > On Mon, Sep 2, 2013 at 6:06 PM, Anthony Papillion <papillion [at] 
>> > gmail.com> wrote:
>> >> Hello Everyone,
>> >>
>> >> I have a multi-line string and I need to remove the very first line
>> >> from it. How can I do that? I looked at StringIO but I can't seem to
>> >> figure out how to properly use it to remove the first line. Basically,
>> >> I want
>> >> to toss the first line but keep everything else.

The maxsplit parameter to str.split makes this easier than falling off a
greased log:


py> astring = """Hello world,
... How are things?
... Hope you are well.
... Goodbye.
... """
py> astring.split("\n", 1)[1]
'How are things?\nHope you are well.\nGoodbye.\n'



-- 
Steven




More information about the Python-list mailing list