Avoiding syntax error for "as" operator in python

I am getting syntax error from python for 'as' statement. I don't know for sure, but I suspect my webserver is outdated python.

x@y.com [~/www/dmi-tcat/helpers]# python urlexpand.py
  File "urlexpand.py", line 70
    except HTTPError as e:
                  ^
SyntaxError: invalid syntax
x@y.com [~/www/dmi-tcat/helpers]# 

      

Can anyone confirm this and is there a way to write the same piece of code without an as statement? My host doesn't want to update python for a minute.

+3


source to share


1 answer


Older python syntax

try:
    ...
except HTTPError, e:
    ...

      



If you want to catch multiple types of errors, pass a tuple:

try:
    ...
except (AttributeError, TypeError), e:
    ...

      

+6


source







All Articles