Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Vincent Davis Newsgroups: comp.lang.python Subject: Try: rather than if : Date: Mon, 14 Dec 2015 15:38:05 -0700 Lines: 16 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de NE3FftDCjxQ1Rs1kHu1aQQL8LW/n6tqnQ8daz7byJeVA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'used.': 0.05; '%s\\n"': 0.09; 'url:github': 0.09; 'received:209.85.218': 0.10; 'def': 0.13; 'another?': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'url:bio': 0.16; 'attribute': 0.18; 'try:': 0.18; 'to:name :python-list@python.org': 0.20; 'pass': 0.22; 'seems': 0.23; 'message-id:@mail.gmail.com': 0.27; 'code': 0.30; 'noticed': 0.32; 'statement': 0.32; 'except': 0.34; 'handle': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'there': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:209': 0.38; 'to:addr:python.org': 0.40; 'url:master': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vincentdavis.net; s=google; h=mime-version:from:date:message-id:subject:to:content-type; bh=/aTjJM//HxSQv6oPL+Ryn/5ZWLqHFYykm2Q1BsBOBfo=; b=olFSD3+DdaJ/y3J17LFJV0drfmZJC/LiQ2Y9LvOgK6z3ieQIEL993RsOYzC+ExIDnm od058ElkaW52V3dYJj1yiSJN0AK78PnRIxAZkiFGpvCs6L4ToNSvmMc7m08vUXjwueKD sUSgMPI6M5JmTV2sdKmIdodgX7GKaHPlhEyic= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to :content-type; bh=/aTjJM//HxSQv6oPL+Ryn/5ZWLqHFYykm2Q1BsBOBfo=; b=meFYdEcqGM6WlIVhVrtqU5K1Nx+kMcmlIyPDcEeLE2HP2C2hokf3rZEJFGFSaSLr8C smeupXMFw4nKQea0QPUCnra8TwkFyl9S1FkGhgh61rj73ud2dmPUXcdVQSmiYTuEdN5d TD/Ja8uUy9JW19jeIUA78cTwCq7X6s9ed++2wUcZjVokw7dcvx32lybd6wKalA4GFUk6 vv6knMQQiSFrUfxyAhg3Sl5kB9YMJYMgY2esCQHOKkHBatYVR2ObKUuv29QoexCq1Ov3 icMSMcEQBIi0NK4VX/Pig0OPlDkCfmGtGikKjDsBeNvyz90OLcr/FlFNXcf11D/MMXOT y7Zg== X-Gm-Message-State: ALoCoQlMLZZQ0PIUa2bMDRYTBfHJQ5sQ8Mvgu3anxD4gYgd5xP+gPwadnGaz/oU6Q0jO2G9leLMmCpQOvKK5l6quEbqiaU+0K6O3JTOWFFRK2fN9t/jXg0k= X-Received: by 10.202.73.209 with SMTP id w200mr25829552oia.85.1450132704623; Mon, 14 Dec 2015 14:38:24 -0800 (PST) X-Content-Filtered-By: Mailman/MimeDel 2.1.20+ X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:100433 In the code below try is used to check if handle has the attribute name. It seems an if statement could be used. Is there reason one way would be better than another? def write_header(self): handle = self.handle try: handle.write("# Report_file: %s\n" % handle.name) except AttributeError: pass handle.write("########################################\n") The specific use case I noticed this was https://github.com/biopython/biopython/blob/master/Bio/AlignIO/EmbossIO.py#L38 Vincent Davis