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


Groups > comp.lang.python > #99932

Re: how to make the below code look better

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: how to make the below code look better
Date Thu, 3 Dec 2015 17:23:50 +1100
Lines 19
Message-ID <mailman.157.1449123833.14615.python-list@python.org> (permalink)
References <CACT3xuXH0j9owTTmyJzdQcEox9fD31tb=zK0dmXnbjiOjqcgUw@mail.gmail.com> <CAPTjJmr04BOCogG3i5SQ5jehqR6q5isHehv1peWEKJ3uj+vYOA@mail.gmail.com> <CACT3xuW22=hcmdByzUmYdfHQfixpmDgMB+Y-oKJyL7cTayVRaA@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de IyBPKjWrgPn/0qmx6EaDKwoRYDevN/Id3ARsbopAJJPg==
Return-Path <rosuav@gmail.com>
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; 'received:209.85.223': 0.03; 'matches': 0.07; 'subject:code': 0.07; 'cc:addr:python- list': 0.09; 'exception,': 0.09; 'handler,': 0.09; 'python': 0.10; 'exception': 0.13; 'syntax': 0.13; 'thu,': 0.15; 'barrier': 0.16; 'comma': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'fruit.': 0.16; 'handling.': 0.16; 'migration.': 0.16; 'received:209.85.223.173': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:make': 0.16; 'wrote:': 0.16; "shouldn't": 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'latter': 0.22; 'bit': 0.23; 'seems': 0.23; 'dec': 0.23; 'header:In-Reply-To:1': 0.24; 'supported': 0.27; 'message-id:@mail.gmail.com': 0.27; 'fine': 0.28; 'code': 0.30; 'convention': 0.30; "i'd": 0.31; 'avoiding': 0.33; 'similar': 0.33; 'received:google.com': 0.35; 'clear': 0.35; 'replace': 0.35; "isn't": 0.35; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'suggestion': 0.37; 'received:209': 0.38; 'subject:the': 0.39; 'your': 0.60; 'avoid': 0.61; 'side': 0.62; "'with'": 0.84; 'all;': 0.84; 'chrisa': 0.84; 'subject:below': 0.84; 'to:none': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=/56JJKFv5Jg7uxMGWMux7Le7UjQqNtUVJPZaK6INxQU=; b=ruCgo7o268FMbLyI0HSnvf8SirMM0EvhV5kRrYpdXirF16hBZtLYnE8CRfisKsiPRi gQ7HJD2tmrFKPlykxr/cQQtcit+d1lPUj2/gpo1iqF64e4ESkS4/SjBVoxEWpRSVQmoC cJm3srw9Le6vOJR/wadTGl6e0jtKoGkVcMOCMokWvjkAkdgOpc3jW7k9LRX+hbicdACF uZU7zkAJPZpUHGzpmeVS7qKWiYHXcBMaOh16qj8sh0mj+okf0gzP8C4eFXJipUlI4pld U6uFhyOkUxKCrgGRk7XHn+uCIFoPhBpceOIK0Gt1BMHn4KEq/+5y26yUOiRdkWcIh9jm VQcQ==
X-Received by 10.107.10.233 with SMTP id 102mr7204679iok.31.1449123830886; Wed, 02 Dec 2015 22:23:50 -0800 (PST)
In-Reply-To <CACT3xuW22=hcmdByzUmYdfHQfixpmDgMB+Y-oKJyL7cTayVRaA@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
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>
Xref csiph.com comp.lang.python:99932

Show key headers only | View raw


On Thu, Dec 3, 2015 at 5:20 PM, Ganesh Pal <ganesh1pal@gmail.com> wrote:
>> The first suggestion I'd make is to avoid the comma syntax for
>> exception handling. Replace "except Exception, e:" with "except
>> Exception as e:". That's a trivial change of syntax that shouldn't
>> affect your code at all; consider it low-hanging fruit.
>>
> ,Are we avoiding  comma syntax because it's a bad convention  or  will
> it have any side effects? In fact I have used this comma syntax in
> most of my code . I will clean the code latter as it seems working
> fine
>

The comma syntax isn't supported in Python 3, so it'll be a barrier to
migration. It's also a bit less clear if you catch multiple exception
types in a single handler, which also uses a comma (to make a tuple).
Also, the 'as' syntax matches up with similar syntax for 'with' and
'import' statements.

ChrisA

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


Thread

Re: how to make the below code look better Chris Angelico <rosuav@gmail.com> - 2015-12-03 17:23 +1100

csiph-web