Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.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.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'yet.': 0.04; 'that?': 0.05; 'string': 0.09; 'subject:string': 0.09; 'toss': 0.09; 'subject:How': 0.10; 'python': 0.11; 'stringio': 0.16; 'subject:remove': 0.16; 'thanks,': 0.17; 'looked': 0.18; 'everyone,': 0.19; 'properly': 0.19; '>>>': 0.22; 'import': 0.22; 'header:In-Reply-To:1': 0.27; 'possibility': 0.29; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; '"",': 0.31; 'anyone': 0.31; 'probably': 0.32; 'figure': 0.32; 'regular': 0.32; 'another': 0.32; 'url:python': 0.33; 'subject:the': 0.34; "can't": 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'url:listinfo': 0.36; 'subject:?': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'to:addr:python- list': 0.38; 'subject:can': 0.39; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'how': 0.40; 'remove': 0.60; 'easy': 0.60; 'expression': 0.60; 'mentioned': 0.61; 'simple': 0.61; 'first': 0.61; 'such': 0.63; 'worth': 0.66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=5SDaHx7ltxFT8Ckt2oDsULTLqejxknIiZRP/59oiFAw=; b=T3MK97PfoDJA+iyEUUldnalpckci+pGcNNi8DytNH9UVqaPlcMbM6Cs4mFYg5LpImv DTH4U6UnpLZUgrKixd/yjDdIqRnJHCTuR4hB65F4AirAsGNBsLHk3heoEDUGshIrtIVo yXh2RoZCeAXLxePSnwA5+Mvsz8Q4oeKOPxqFKvh+IpaeT7IAnvlgfmBqpNcQ/cA3T+NB +uJwvJSodkQL8KkLrybCuYi2rcgZB7xozNm6fQKbVCvDBQAKco4BURmJRKH8rimn9jn7 E3qOytBlNFnXdLSMhy26nsBpF9XjEpbPBcMstKBoj+vq2qtNU97Ol6q/vYN8ysERHZ0o bKGw== MIME-Version: 1.0 X-Received: by 10.182.61.44 with SMTP id m12mr17465257obr.52.1378142316583; Mon, 02 Sep 2013 10:18:36 -0700 (PDT) In-Reply-To: <5224B786.2050606@gmail.com> References: <5224B786.2050606@gmail.com> Date: Mon, 2 Sep 2013 19:18:36 +0200 Subject: Re: How can I remove the first line of a multi-line string? From: Vlastimil Brom To: python Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1378142319 news.xs4all.nl 15952 [2001:888:2000:d::a6]:38222 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:53510 2013/9/2 Anthony Papillion : > 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 Hi, it is probably not worth it for such simple replacement, but just to add another possibility to the already mentioned methods - you can use regular expression replacement: >>> import re >>> re.sub(r"^.*\n", "", "abc\ndef\nghi") 'def\nghi' >>> hth, vbr