Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Help resolve a syntax error on 'as' keyword (python 2.5)

Reply
Thread Tools

Help resolve a syntax error on 'as' keyword (python 2.5)

 
 
Oltmans
Guest
Posts: n/a
 
      11-03-2009
Hi, all. All I'm trying to do is to print the error message using the
following code (copying/pasting from IDLE).

def div(a,b):
print a/b


try:
div(5,0)
except Exception as msg:
print msg

but IDLE says (while highlighting the 'as' keyword)
except Exception as msg:

SyntaxError: invalid syntax

I've searched the internet and I'm not sure what can cause this. Any
help is highly appreciated. I'm using Python 2.5 on Windows XP.
 
Reply With Quote
 
 
 
 
Vladimir Ignatov
Guest
Posts: n/a
 
      11-03-2009
Hi,

"except Exception as variable"

is a new python-3 syntax.

You should use "except Exception, variable" syntax in 2.x series.

Vladimir Ignatov



On Tue, Nov 3, 2009 at 4:06 PM, Oltmans <(E-Mail Removed)> wrote:
> Hi, all. All I'm trying to do is to print the error message using the
> following code (copying/pasting from IDLE).
>
> def div(a,b):
> * * * *print a/b
>
>
> try:
> * *div(5,0)
> except Exception as msg:
> * *print msg
>
> but IDLE says (while highlighting the 'as' keyword)
> except Exception as msg:
>
> SyntaxError: invalid syntax
>
> I've searched the internet and I'm not sure what can cause this. Any
> help is highly appreciated. I'm using Python 2.5 on Windows XP.

 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      11-03-2009
Vladimir Ignatov wrote:

> Hi,
>
> "except Exception as variable"
>
> is a new python-3 syntax.
>
> You should use "except Exception, variable" syntax in 2.x series.


Not entirely true. This feature has been backported to python2.6 as well.

Diez
 
Reply With Quote
 
Gabriel Genellina
Guest
Posts: n/a
 
      11-04-2009
En Tue, 03 Nov 2009 10:06:24 -0300, Oltmans <(E-Mail Removed)>
escribió:

> Hi, all. All I'm trying to do is to print the error message using the
> following code (copying/pasting from IDLE).
>
> try:
> div(5,0)
> except Exception as msg:
> print msg
>
> SyntaxError: invalid syntax
>
> I'm using Python 2.5 on Windows XP.


Other people already told you what the problem is.
I suggest reading a book/tutorial written for the *same* Python version
you're using (2.x; it doesn't matter 2.6, 2.5, 2.4...).
Once you know the basics of the language, you may look at the differences
in the "What's new?" document for Python 3.0 - but right now, they will
just confuse you.

--
Gabriel Genellina

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
any idea to resolve this ambigous syntax in my Spirit grammar galopin C++ 0 05-09-2009 04:07 PM
Syntax error? What syntax error? Assignment fo default values? Mark Richards Perl Misc 3 11-18-2007 05:01 PM
RE: keyword checker - keyword.kwlist Hamilton, William Python 4 05-13-2007 06:31 AM
keyword checker - keyword.kwlist tom@finland.com Python 6 05-10-2007 04:53 PM
src-resolve: Cannot resolve the name ... ivanet@gmail.com XML 1 03-23-2007 12:10 PM



Advertisments