Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #53501

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

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <oscar.j.benjamin@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'yet.': 0.04; 'that?': 0.05; 'string': 0.09; 'subject:string': 0.09; 'toss': 0.09; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; 'cc:name:python list': 0.16; 'stringio': 0.16; 'subject:remove': 0.16; 'wrote:': 0.18; 'looked': 0.18; 'everyone,': 0.19; 'pfxlen:0': 0.19; 'properly': 0.19; "skip:' 30": 0.19; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'header:In- Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'lines': 0.31; 'anyone': 0.31; 'probably': 0.32; 'figure': 0.32; 'subject:the': 0.34; "can't": 0.35; 'but': 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'subject:can': 0.39; 'how': 0.40; 'remove': 0.60; 'easy': 0.60; 'new': 0.61; 'first': 0.61; 'to:addr:gmail.com': 0.65; 'oscar': 0.84; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=5yy2YR2OURd8zYBCp5gfDhKRZe82FdNy+buFnVFNAsU=; b=JIndackLJHcmB31WmO88iAnOaUNjvHv8oC6z5jhfZqqHCRcj8dgWUoMcijWg5PVYsB J6XVMIsPnS0khJG3IF5cJ2ya3tHQv7NzLC2PcXSDBIyuTP7jJ0opRW1mZ4c0I5Y8dmnJ HLoqXDUKrQg3hKh4ZnNZnBjag5I2E0zr1+Jiz+y6ZwPH3Y3iimFkQqz4PgcY2W8qLIrD EJfsX/7xBvMpOpJS7x85O9N+8RXbuGrbJ+XGkRO76W9oQ1+xJzt2689HHJc/nDNFdCG9 q8ih53dl1XktVjeCs5VmCE3FzBNXkxOld9q8IaBzdsMcOWPv9F8vCs7aW2hPUzMcSbnI ND3Q==
X-Received by 10.52.173.165 with SMTP id bl5mr6430972vdc.18.1378138726577; Mon, 02 Sep 2013 09:18:46 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <5224B786.2050606@gmail.com>
References <5224B786.2050606@gmail.com>
From Oscar Benjamin <oscar.j.benjamin@gmail.com>
Date Mon, 2 Sep 2013 17:18:26 +0100
Subject Re: How can I remove the first line of a multi-line string?
To Anthony Papillion <papillion@gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Cc Python List <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.499.1378138729.19984.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1378138729 news.xs4all.nl 15986 [2001:888:2000:d::a6]:42371
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:53501

Show key headers only | View raw


On 2 September 2013 17:06, Anthony Papillion <papillion@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.  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.

>>> a = '''asd
... qwe
... rty'''
>>> print(a)
asd
qwe
rty
>>> a.splitlines()
['asd', 'qwe', 'rty']
>>> a.splitlines(True)  # Keep the new lines
['asd\n', 'qwe\n', 'rty']
>>> a.splitlines(True)[1:]  # remove first line
['qwe\n', 'rty']
>>> ''.join(a.splitlines(True)[1:]) # recombine
'qwe\nrty'
>>> a = ''.join(a.splitlines(True)[1:])
>>> print(a)
qwe
rty


Oscar

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: How can I remove the first line of a multi-line string? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-09-02 17:18 +0100

csiph-web