Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #53499
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!newsfeed.kamp.net!newsfeed.kamp.net!87.79.20.101.MISMATCH!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <kwpolska@gmail.com> |
| 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; 'utf-8': 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; 'pfxlen:0': 0.19; 'properly': 0.19; "skip:' 30": 0.19; 'cc:addr:python.org': 0.22; '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; 'message-id:@mail.gmail.com': 0.30; 'along': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'sep': 0.31; 'anyone': 0.31; 'probably': 0.32; 'figure': 0.32; 'url:python': 0.33; 'sense': 0.34; 'subject:the': 0.34; "can't": 0.35; 'but': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'list': 0.37; 'pm,': 0.38; 'does': 0.39; 'subject:can': 0.39; 'url:mail': 0.40; 'how': 0.40; 'remove': 0.60; 'easy': 0.60; 'from:charset:utf-8': 0.61; 'first': 0.61; 'making': 0.63; 'skip:\xe2 10': 0.65; 'to:addr:gmail.com': 0.65; '8bit%:43': 0.74; 'url:tk': 0.95; '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:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=QMd3W5BaRGZuMsDvfqzbQvGRA4JELaUhD3UndyPIAdg=; b=j3A/bAPBodatw7SMXEiIC21YyS8RKkundsFVztKjEaw6c79zx8fg2DKdHhfSrEe0mV 4cpQvyhpCeqrwtiIRwlqymEmJ5mzf1gOQeUdHjIyStgc/HMDsW5puSPWlmYvUGSUViqT 6w0DGU3KW4nWdpU68gT+rZZErxER5ptl3U+qjrS5mlVm5PZX20cO5l/4g2411/FW2HDE 3TYudCMj+HMVSZ8a126BXRvf8OF+dgr1vv2mbjEjpxAGRWzuoZIx4W6xaq2+6JexhI9p 9ybDkkcYfKjBZv13dkxpmnt68p/X9TQxbbXEpsZpAKV8vJ2RLj5w/1WasCkopLbVD5BA re0Q== |
| MIME-Version | 1.0 |
| X-Received | by 10.220.186.202 with SMTP id ct10mr24204159vcb.14.1378138355717; Mon, 02 Sep 2013 09:12:35 -0700 (PDT) |
| In-Reply-To | <5224B786.2050606@gmail.com> |
| References | <5224B786.2050606@gmail.com> |
| Date | Mon, 2 Sep 2013 18:12:35 +0200 |
| Subject | Re: How can I remove the first line of a multi-line string? |
| From | Chris “Kwpolska” Warrick <kwpolska@gmail.com> |
| To | Anthony Papillion <papillion@gmail.com> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| 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.498.1378138364.19984.python-list@python.org> (permalink) |
| Lines | 35 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1378138364 news.xs4all.nl 15970 [2001:888:2000:d::a6]:39401 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:53499 |
Show key headers only | View raw
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""")
--
Chris “Kwpolska” Warrick <http://kwpolska.tk>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: How can I remove the first line of a multi-line string? Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2013-09-02 18:12 +0200
csiph-web