Re: Short syntax for try/pass

2014-10-14 Thread Chris Angelico
On Wed, Oct 15, 2014 at 1:28 AM, Ned Batchelder wrote: > PEP 463 proposes a short syntax for this use case: > http://legacy.python.org/dev/peps/pep-0463/ > > I'm not sure what became of it. Not quite; PEP 463 is about the case where you then want a different value instead. I'm fairly sure the PEP

Re: Short syntax for try/pass

2014-10-14 Thread Ned Batchelder
On 10/14/14 10:08 AM, Leonardo Giordani wrote: Would it be feasible to propose a short syntax like this? pass SomeException: somecode where the above example would become: pass IndexError: lst[0] = lst[0] + 1 I could not find if such a syntax has been already discussed elsewhere, so plea

Re: Short syntax for try/pass

2014-10-14 Thread Chris Angelico
On Wed, Oct 15, 2014 at 1:08 AM, Leonardo Giordani wrote: > a lot of times the following pattern pops out in Python code: > > try: > somecode > except SomeException: > pass > > Converting the code to a non-EAFP version, for example > > if len(lst) != 0: > lst[0] = lst[0] + 1 This could be just

Short syntax for try/pass

2014-10-14 Thread Leonardo Giordani
Hi all, a lot of times the following pattern pops out in Python code: try: somecode except SomeException: pass A very simple example could be if you want to process a list that may be empty def process_list(lst): try: lst[0] = lst[0] + 1 except IndexError: pass or in more complex cases