Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'completeness': 0.07; 'exist,': 0.07; 'subject:How': 0.09; 'formatted': 0.09; 'received:155': 0.09; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'example).': 0.16; 'fld': 0.16; 'from:addr:jpmorgan.com': 0.16; 'received:155.180': 0.16; 'received:159.53': 0.16; 'received:bankone.net': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'received:svr.bankone.net': 0.16; 'securities,': 0.16; 'statement.': 0.16; 'subject:exists': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'wrote:': 0.17; 'to:name:python- list@python.org': 0.20; 'elements': 0.23; 'received:169.254': 0.24; 'thus': 0.24; 'header:In-Reply-To:1': 0.25; '(most': 0.27; 'accuracy': 0.27; 'set.': 0.27; "doesn't": 0.28; 'received:169': 0.29; 'e.g.': 0.30; 'header:Received:8': 0.30; 'could': 0.32; 'print': 0.32; 'to:addr:python-list': 0.33; 'list': 0.35; 'exist': 0.35; 'subject:?': 0.35; 'there': 0.35; 'but': 0.36; 'charset:us- ascii': 0.36; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'day,': 0.60; 'series': 0.63; 'information,': 0.63; 'url:email': 0.63; 'more': 0.63; 'become': 0.65; 'legal': 0.65; 'subject': 0.66; 'purchase': 0.67; 'sale': 0.76; 'balance,': 0.84; 'received:169.254.8': 0.84 X-DKIM: OpenDKIM Filter v2.1.3 sz2.jpmchase.com q8DHmIPk014499 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpmorgan.com; s=smtpout; t=1347558499; bh=CIg61cS+GnfyJozOSIoe2cXfo5XLnYJR1NNXSDHi5F8=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Transfer-Encoding:MIME-Version:Content-Type; b=sq3m3Y2dQNBAIFNPPGTCiyiw55xbUiNJWRl4A1JRhZ5Ds4rMOF/9oyNeQf2WooYp+ 3kgpJltbish7KQfR0UzC+NDPCaygDYoTxR/Dj3X/iartmts7WUsK/dh9hzDLvGSwM8 UNDg0atA7N0DZFe55fHR0HuyDT8zNhUzV/kF9u98= From: "Prasad, Ramit" To: "python-list@python.org" Subject: RE: How to print something only if it exists? Thread-Topic: How to print something only if it exists? Thread-Index: AQHNjFoqx2N+Mknpa0O9RK2rpfTRFJeIlnxw Date: Thu, 13 Sep 2012 17:48:06 +0000 References: <9s4nh9-8dr.ln1@chris.zbmc.eu> In-Reply-To: <9s4nh9-8dr.ln1@chris.zbmc.eu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.67.79.47] Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-DLP-FWD: Yes Content-Type: text/plain; charset="us-ascii" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 16 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1347559650 news.xs4all.nl 6853 [2001:888:2000:d::a6]:39916 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29060 tinnews@isbd=2Eco=2Euk wrote:=0D=0A> I want to print a series of list eleme= nts some of which may not exist,=0D=0A> e=2Eg=2E I have a line:-=0D=0A> =0D= =0A> print day, fld[1], balance, fld[2]=0D=0A> =0D=0A> fld[2] doesn't = always exist (fld is the result of a split) so the=0D=0A> print fails when = it isn't set=2E=0D=0A> =0D=0A> I know I could simply use an if but ultimate= ly there may be more=0D=0A> elements of fld in the print and the print may = well become more=0D=0A> complex (most like will be formatted for example)= =2E Thus it would be=0D=0A> good if there was some way to say "print this = if it exists"=2E=0D=0A=0D=0AYou can use an inline if-else statement=2E=0D= =0A=0D=0Aprint day, fld[1], balance, fld[2] if len(fld) >=3D 3 else ''=0D= =0A=0D=0A=0D=0ARamit=0D=0A--=0D=0A=0D=0AThis email is confidential and subj= ect to important disclaimers and=0D=0Aconditions including on offers for th= e purchase or sale of=0D=0Asecurities, accuracy and completeness of informa= tion, viruses,=0D=0Aconfidentiality, legal privilege, and legal entity disc= laimers,=0D=0Aavailable at http://www=2Ejpmorgan=2Ecom/pages/disclosures/em= ail=2E