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


Groups > comp.lang.python > #45436

Re: spilt question

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ned@nedbatchelder.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'string': 0.09; 'underscore': 0.09; 'subject:question': 0.10; 'cc:addr:python- list': 0.11; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'wrote:': 0.18; 'split': 0.19; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; '&gt;&gt;&gt;': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'appreciated': 0.26; 'skip:" 30': 0.26; 'skip:" 40': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'am,': 0.29; 'work.': 0.31; 'getting': 0.31; "skip:' 10": 0.31; 'but': 0.35; 'should': 0.36; 'skip:[ 10': 0.38; 'show': 0.63; 'to:addr:gmail.com': 0.65; 'future,': 0.83
Date Thu, 16 May 2013 11:22:15 -0400
From Ned Batchelder <ned@nedbatchelder.com>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6
MIME-Version 1.0
To loial <jldunn2000@gmail.com>
Subject Re: spilt question
References <d8c03de0-dc35-45e3-a6b2-2af39feb9e79@googlegroups.com>
In-Reply-To <d8c03de0-dc35-45e3-a6b2-2af39feb9e79@googlegroups.com>
Content-Type multipart/alternative; boundary="------------010204000303020303000900"
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.1761.1368717742.3114.python-list@python.org> (permalink)
Lines 74
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1368717742 news.xs4all.nl 15966 [2001:888:2000:d::a6]:41851
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:45436

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On 5/16/2013 11:00 AM, loial wrote:
> I want to split a string so that I always return everything BEFORE the LAST underscore
>
> HELLO_xxxxxxxx.lst         # should return HELLO
> HELLO_GOODBYE_xxxxxxxx.ls  # should return HELLO_GOODBYE
>
> I have tried with rsplit but cannot get it to work.
>
> Any help appreciated
>
     >>> "HELLO_GOODBYE_xxxxxxxx.ls".rpartition('_')
    ('HELLO_GOODBYE', '_', 'xxxxxxxx.ls')
     >>> "HELLO_GOODBYE_xxxxxxxx.ls".rsplit('_', 1)
    ['HELLO_GOODBYE', 'xxxxxxxx.ls']
     >>> "HELLO_GOODBYE_xxxxxxxx.ls".rpartition('_')[0]
    'HELLO_GOODBYE'
     >>> "HELLO_GOODBYE_xxxxxxxx.ls".rsplit('_', 1)[0]
    'HELLO_GOODBYE'


For the future, getting help works better if you show what you tried, 
and what it produced.

--Ned.

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


Thread

spilt question loial <jldunn2000@gmail.com> - 2013-05-16 08:00 -0700
  Re: spilt question Walter Hurry <walterhurry@lavabit.com> - 2013-05-16 15:10 +0000
  Re: spilt question Fábio Santos <fabiosantosart@gmail.com> - 2013-05-16 16:14 +0100
  Re: spilt question Chris Angelico <rosuav@gmail.com> - 2013-05-17 01:15 +1000
  Re: spilt question Dave Angel <davea@davea.name> - 2013-05-16 11:20 -0400
  Re: spilt question Tim Chase <python.list@tim.thechases.com> - 2013-05-16 10:23 -0500
  Re: spilt question Ned Batchelder <ned@nedbatchelder.com> - 2013-05-16 11:22 -0400
  Re: spilt question Dave Angel <davea@davea.name> - 2013-05-16 11:32 -0400

csiph-web