Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.016 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; "(it's": 0.09; '-1.': 0.09; 'prefix': 0.09; 'am,': 0.14; 'wrote:': 0.14; 'except:': 0.16; 'missing,': 0.16; 'unhandled': 0.16; 'cc:addr:python-list': 0.17; 'mon,': 0.17; 'cheers,': 0.19; 'header:In-Reply-To:1': 0.21; 'cc:2**0': 0.22; 'cc:no real name:2**0': 0.23; 'clause': 0.23; 'received:209.85.161.46': 0.23; 'received:mail- fx0-f46.google.com': 0.23; 'fix': 0.23; 'received:209.85.161': 0.26; 'string': 0.26; 'message-id:@mail.gmail.com': 0.28; 'checking': 0.29; 'subject:how': 0.29; 'bit': 0.30; 'cc:addr:python.org': 0.30; 'second': 0.30; 'catching': 0.30; 'it.': 0.31; 'things': 0.33; 'that,': 0.34; 'there': 0.35; 'like:': 0.35; 'using': 0.35; 'received:google.com': 0.37; 'something': 0.37; 'received:209.85': 0.37; 'fair': 0.37; 'two': 0.37; 'could': 0.38; 'but': 0.38; 'subject:: ': 0.38; 'received:209': 0.39; 'either': 0.39; 'possibility': 0.40; 'really': 0.40; 'addition': 0.60; 'enough,': 0.65; 'for).': 0.91; 'magical': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type:content-transfer-encoding; bh=Y5WmBfPiLkxJXrbXZNavnUH+61KyolrFjp27UYtS7U4=; b=ARPuGXRbdcztew7+m1wKRWZK5bX/FW20qvzeuS7jEkv/RmKLPFEJxvQ2Y27OQjN/ob iW8wy4GYt7qMJeSksHc5CKrEQ6s+ksDN+E2xajthot77lvyIMl22cGpngohzhmym7XAZ 2XEbPmNgyhETgaK0wS9Mb5n5gPtUrxxk6X9fE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=jj0lFjGnyca0A1IFd33kUdI3aUWPanf0afziEbkk2vTUT2nCOIeI6G+rN1CtPpTXCh 8Fn87byPboyUxFnEY5GW6VA/p7MaSXH744ZiNh16wV3jRgUJBPHnl62ZxMOWYrpxAotR z1h43928TPUjZ9YtLMCEsp0X9+3X7e9MQp5VA= MIME-Version: 1.0 In-Reply-To: <954gd8Fh73U1@mid.individual.net> References: <9e861b0e-e768-401b-b5ca-190f20830a08@s9g2000yqm.googlegroups.com> <94ph22FrhvU5@mid.individual.net> <4de8eef1$0$29996$c3e8da3$5496439d@news.astraweb.com> <1237a287-10b0-4a2d-ba35-97b5238deda1@n11g2000yqf.googlegroups.com> <94svm4Fe7eU1@mid.individual.net> <65164054-f11d-4f8e-a141-31513e70ca04@h9g2000yqk.googlegroups.com> <954cb5F5qbU1@mid.individual.net> <954gd8Fh73U1@mid.individual.net> From: Ian Kelly Date: Mon, 6 Jun 2011 11:40:51 -0600 Subject: Re: how to avoid leading white spaces To: Neil Cerutti Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 22 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1307382083 news.xs4all.nl 49048 [::ffff:82.94.164.166]:49380 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7099 On Mon, Jun 6, 2011 at 11:17 AM, Neil Cerutti wrote: > I wrestled with using addition like that, and decided against it. > The 7 is a magic number and repeats/hides information. I wanted > something like: > > =A0 prefix =3D "TABLE=3D'" > =A0 start =3D line.index(prefix) + len(prefix) > > But decided I searching for the opening ' was a bit better. Fair enough, although if you ask me the + 1 is just as magical as the + 7 (it's still the length of the string that you're searching for). Also, re-finding the opening ' still repeats information. The main thing I wanted to fix was that the second .index() call had the possibility of raising an unhandled ValueError. There are really two things we have to search for in the line, either of which could be missing, and catching them both with the same except: clause feels better to me than checking both of them for -1. Cheers, Ian