0

I am working with a git repo that is showing syntax error for "except Exception, e:"

I am using Python 2.7.

which python version supports syntax like "except Exception, e"?

3
  • Switch it to 'except Exception as e:' Commented Apr 14, 2022 at 6:41
  • 2
    This syntax was removed in Python 3. And Python 2 is no more. It has ceased to be. Bereft of life, it rests in peace. It has kicked the bucked and joined the choir invisible. It's ex-Python. Commented Apr 14, 2022 at 6:44
  • Is there any way to run the code as it is, without doing any changes in the source code Commented Apr 14, 2022 at 7:01

3 Answers 3

2
except Exception, e

In Python 3.x the syntax is:

except Exception as e:
    ...

As you can see here the same syntax was used in version 2.7.

Sign up to request clarification or add additional context in comments.

Comments

1
except Exception,e:

same syntax with:

except Exception as e:

Its not related with python version, You may look PEP document.

PEP 3110: "Catching Exceptions in Python 3000"

2 Comments

Right, it's not related with Python version, I knew this but I had never read that PEP, thank you. +1
"stynax" => "syntax" ;-)
0

What you are looking for is:

                try:
                    do_sth()
                except Exception as ex:
                    traceback.print_exc()
                    print(ex.message)
                    print(ex.args)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.