Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #53502
| Path | csiph.com!usenet.pasdenom.info!news.franciliens.net!news.muarf.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <papillion@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*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; 'cc:addr:python-list': 0.11; 'python': 0.11; 'element,': 0.16; 'newlines': 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; 'cc:addr:python.org': 0.22; 'header:User- Agent:1': 0.23; 'finally,': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'this:': 0.26; 'header:In-Reply- To:1': 0.27; 'chris': 0.29; 'am,': 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; 'worked': 0.33; 'url:python': 0.33; 'subject:the': 0.34; "can't": 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'url:listinfo': 0.36; 'doing': 0.36; 'url:org': 0.36; 'list': 0.37; 'message- id:@gmail.com': 0.38; 'thank': 0.38; 'pm,': 0.38; 'does': 0.39; 'subject:can': 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; 'to:addr:gmail.com': 0.65; 'study': 0.69; '8bit%:43': 0.74; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=wcepKdXBdBBhOd5V19lPVOA6KCUk7umo9JlOuOpSanI=; b=DGt+xWB4bgDjtoqxk0Kttk+bEL+JvsJhzUsqzmIeArNyVauUDIH8TH6zfkQG13I/2Y VHdqHkqnagbr5XXEel00xeRy000C96xBOKI/FboI0KkJz5cF6lUZUN/wB5bYtqt8Gxzu SfHe+HOsM2SwztGkLY4cUtLcsX0S2e7s2y9sfq7d/pweCLZW3I+OYaZ9CLm0MjhuxHQ4 yLwFRTLsW3mX6RU2xCnM4ZLGALNvyJeGVlN4XIf+1YSuoKGqbcZCigbgxzTIPz6YMQXT lbfgvqynzYXUvn+9s2EfO8iHg014awNULdS+eWzKYxA5E0EEB0wIfRY5bMK7rrwGvp7c yweQ== |
| X-Received | by 10.182.113.195 with SMTP id ja3mr17849290obb.46.1378139048402; Mon, 02 Sep 2013 09:24:08 -0700 (PDT) |
| Date | Mon, 02 Sep 2013 11:24:06 -0500 |
| From | Anthony Papillion <papillion@gmail.com> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130804 Thunderbird/17.0.8 |
| MIME-Version | 1.0 |
| To | Chris “Kwpolska” Warrick <kwpolska@gmail.com> |
| Subject | Re: How can I remove the first line of a multi-line string? (SOLVED) |
| References | <5224B786.2050606@gmail.com> <CAMw+j7Lp8v49qqSsq9TzevxNz1jWs=rNNbhYdF8NmPfYSi82GA@mail.gmail.com> |
| In-Reply-To | <CAMw+j7Lp8v49qqSsq9TzevxNz1jWs=rNNbhYdF8NmPfYSi82GA@mail.gmail.com> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| Cc | 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.500.1378139057.19984.python-list@python.org> (permalink) |
| Lines | 38 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1378139057 news.xs4all.nl 15869 [2001:888:2000:d::a6]:47878 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:53502 |
Show key headers only | View raw
On 09/02/2013 11:12 AM, Chris “Kwpolska” Warrick wrote:
> On Mon, Sep 2, 2013 at 6:06 PM, 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.
>>
>> 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""")
This, of course, worked like a charm. I really need to study the string
methods. In the work I'm doing they are going to come in very handy.
Thank you, Chris!
Anthony
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: How can I remove the first line of a multi-line string? (SOLVED) Anthony Papillion <papillion@gmail.com> - 2013-09-02 11:24 -0500
Re: How can I remove the first line of a multi-line string? (SOLVED) Roy Smith <roy@panix.com> - 2013-09-02 13:07 -0400
Re: How can I remove the first line of a multi-line string? (SOLVED) Fábio Santos <fabiosantosart@gmail.com> - 2013-09-11 13:08 +0100
Re: How can I remove the first line of a multi-line string? (SOLVED) Roy Smith <roy@panix.com> - 2013-09-11 09:03 -0400
Re: How can I remove the first line of a multi-line string? (SOLVED) Terry Reedy <tjreedy@udel.edu> - 2013-09-11 08:42 -0400
csiph-web