joep1
joep1

Reputation: 323

Avoiding syntax error for 'as' statement in python

I am getting a syntax error from python for the 'as' statement. I don't know for sure but I suspect my web server has out of date python.

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

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

Upvotes: 3

Views: 949

Answers (1)

Greg
Greg

Reputation: 10352

The older python syntax is

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

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

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

Upvotes: 6

Related Questions