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


Groups > comp.lang.python > #80398

Re: How do i reduce this to a single function - the code is largely similar, just a direction of search toggle.

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:code': 0.07; 'line:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:How': 0.10; 'def': 0.12; '"def"': 0.16; "(it's": 0.16; 'buffer,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'stepping': 0.16; 'subject: \n ': 0.16; 'subject:search': 0.16; 'token,': 0.16; 'index': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'trying': 0.19; 'code,': 0.22; 'header:User-Agent:1': 0.23; 'case.': 0.24; 'received:comcast.net': 0.24; 'sort': 0.25; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'mode': 0.30; 'lines': 0.31; 'text': 0.33; 'subject:the': 0.34; 'could': 0.34; 'editor': 0.35; 'but': 0.35; 'searching': 0.37; 'two': 0.37; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'first': 0.61; 'back': 0.62; 'skip:n 10': 0.64; 'different': 0.65; 'fact,': 0.69; 'subject:this': 0.83
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Ned Batchelder <ned@nedbatchelder.com>
Subject Re: How do i reduce this to a single function - the code is largely similar, just a direction of search toggle.
Date Sat, 08 Nov 2014 07:56:46 -0500
References <m3i9lp$8fp$1@dont-email.me> <m3insb$s06$1@dont-email.me> <m3iprd$8aq$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host c-50-133-228-126.hsd1.ma.comcast.net
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.6.0
In-Reply-To <m3iprd$8aq$1@dont-email.me>
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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15581.1415451417.18130.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1415451417 news.xs4all.nl 2833 [2001:888:2000:d::a6]:53190
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:80398

Show key headers only | View raw


On 11/7/14 9:52 AM, Veek M wrote:
> Veek M wrote:
>
>
>>                  new_col = self.b[row].index('def')
>>                  self.w.cursor = row, new_col
>
>>                  new_col = self.b[row].rindex('def')
>>                  self.w.cursor = row, new_col
>
> There's also the different methods index vs rindex. Does this sort of thing
> justify two functions and associated infrastructure (it's for vim so 2 x 3
> mode lines in my .vimrc)
>

Stepping back a bit from the lines of code, why do you need to use 
.index in one case and .rindex in the other?  You are trying to find the 
"def" line in the editor buffer, either above the current point, or 
below it.  But the "def" will always be the first non-whitespace text on 
the line.   In fact, when searching upward, you could find this line:

     def get_default(self):

and you want to end up on the "def" token, not the "def" in 
"get_default".  .rindex isn't what you want in any case.  Use .index in 
both cases.

-- 
Ned Batchelder, http://nedbatchelder.com

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


Thread

How do i reduce this to a single function - the code is largely similar, just a direction of search toggle. Veek M <vek.m1234@gmail.com> - 2014-11-07 16:46 +0630
  Re: How do i reduce this to a single function - the code is largely similar, just a direction of search toggle. Joel Goldstick <joel.goldstick@gmail.com> - 2014-11-07 16:18 -0500
  Re: How do i reduce this to a single function - the code is largely similar, just a direction of search toggle. Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-07 22:22 +0000
  Re: How do i reduce this to a single function - the code is largely similar, just a direction of search toggle. Chris Angelico <rosuav@gmail.com> - 2014-11-08 09:31 +1100
  Re: How do i reduce this to a single function - the code is largely similar, just a direction of search toggle. Veek M <vek.m1234@gmail.com> - 2014-11-07 21:22 +0630
    Re: How do i reduce this to a single function - the code is largely similar, just a direction of search toggle. Ned Batchelder <ned@nedbatchelder.com> - 2014-11-08 07:56 -0500
      Re: How do i reduce this to a single function - the code is largely similar, just a direction of search toggle. Veek M <vek.m1234@gmail.com> - 2014-11-09 15:15 +0630
  Re: How do i reduce this to a single function - the code is largely similar, just a direction of search toggle. Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-07 15:18 +0000

csiph-web