how to make the below code look better

Chris Angelico rosuav at gmail.com
Thu Dec 3 01:23:50 EST 2015


On Thu, Dec 3, 2015 at 5:20 PM, Ganesh Pal <ganesh1pal at 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



More information about the Python-list mailing list