Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'yet.': 0.04; 'that?': 0.05; 'removes': 0.07; 'string': 0.09; 'subject:string': 0.09; 'toss': 0.09; 'subject:How': 0.10; 'python': 0.11; 'element,': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'newlines': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'separated': 0.16; 'stringio': 0.16; 'subject:remove': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'looked': 0.18; 'everyone,': 0.19; 'properly': 0.19; "skip:' 30": 0.19; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'finally,': 0.24; 'mon,': 0.24; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'along': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'sep': 0.31; 'anyone': 0.31; 'probably': 0.32; 'figure': 0.32; 'another': 0.32; 'url:python': 0.33; 'subject:the': 0.34; "can't": 0.35; 'received:84': 0.35; 'but': 0.35; 'url:listinfo': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'list': 0.37; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'does': 0.39; 'subject:can': 0.39; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'how': 0.40; 'remove': 0.60; 'easy': 0.60; 'first': 0.61; 'making': 0.63; 'skip:\xe2 10': 0.65; 'header:Reply-To:1': 0.67; 'reply-to:no real name:2**0': 0.71; '8bit%:43': 0.74; 'reply-to:addr:python.org': 0.84; '2013': 0.98 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=ZMDuxxLb c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=0kkAYlmtguIA:10 a=vlBx-IyM-_oA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=eF6wUrwl7MQA:10 a=pGLkceISAAAA:8 a=Qfr_SZnxI_CvcmS0V0kA:9 a=QEXdDO2ut3YA:10 a=MSl-tDqOz04A:10 X-AUTH: mrabarnett:2500 Date: Mon, 02 Sep 2013 17:53:32 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: python-list@python.org Subject: Re: How can I remove the first line of a multi-line string? References: <5224B786.2050606@gmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1378140794 news.xs4all.nl 15924 [2001:888:2000:d::a6]:51111 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:53503 On 02/09/2013 17:12, Chris “Kwpolska” Warrick wrote: > On Mon, Sep 2, 2013 at 6:06 PM, Anthony Papillion 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. Can anyone put me on >> the right path? I know it is probably easy but I'm still learning Python >> and don't have all the string functions down yet. >> >> Thanks, >> Anthony >> -- >> http://mail.python.org/mailman/listinfo/python-list > > Use split() and join() methods of strings, along with slicing. Like this: > > fullstring = """foo > bar > baz""" > > sansfirstline = '\n'.join(fullstring.split('\n')[1:]) > > The last line does this: > 1. fullstring.split('\n') turns it into a list of ['foo', 'bar', 'baz'] > 2. the [1:] slice removes the first element, making it ['bar', 'baz'] > 3. Finally, '\n'.join() turns the list into a string separated by > newlines ("""bar > baz""") > Another way is to use .partition: >>> fullstring = """foo\nbar\nbaz""" >>> fullstring.partition("\n")[2] 'bar\nbaz'