[Tutor] Weird Try..Except Error

Peter Otten __peter__ at web.de
Fri Nov 25 12:58:07 CET 2011


Nikunj.Badjatya at emc.com wrote:

> Please look at the snippet below.
> When I am running my module its giving me following error.
> Using : Python 2.7, windows Env.
> 
> {{{
> # User defined modules
> try:
>     from scripts import precheck
>     from scripts import input
>     from scripts import validate
>     from scripts import logsetup
>     from scripts.constants import *
> except ImportError, err_msg:                  ==> line 38
>     print("ERROR {0}".format(err_msg))
>     print("INFO  Please verify the presence of above module, and restart
>     the installation") sys.exit(1)
> 
> }}}
> 
> {{{
> Output:
> 
> C:\> install.py -f input.xml
>   File " C:\>install.py", line 38
>     except ImportError, err_msg:
>                       ^
> SyntaxError: invalid syntax
> }}}
> 
> I checked the comma and spacing and didn't find any problem.
> 
> Any idea.?

You are likely mistaken about the Python version you are using. The above 
error will be triggered by Python 3.x which expects

try:
    ...
except ImportError as err_msg:
    ...




More information about the Tutor mailing list