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


Groups > comp.lang.python > #99932 > unrolled thread

Re: how to make the below code look better

Started byChris Angelico <rosuav@gmail.com>
First post2015-12-03 17:23 +1100
Last post2015-12-03 17:23 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#99932 — Re: how to make the below code look better

FromChris Angelico <rosuav@gmail.com>
Date2015-12-03 17:23 +1100
SubjectRe: how to make the below code look better
Message-ID<mailman.157.1449123833.14615.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web