Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: What am I doing wrong here?

Reply
Thread Tools

Re: What am I doing wrong here?

 
 
=?ISO-8859-1?Q?Gerhard_H=E4ring?=
Guest
Posts: n/a
 
      06-30-2003
Bill C. Wong wrote:

> ################################
> def func( s ):
> s1, s2 = s.split( ' ', 1 )
> try:
> raise s1
> except "aaaa":
> print 'except "aaaa"'
> except:
> print 'except:'
>
> s = "aaaa "
> func( s )
> ################################
> If I manually assign s1 with s1 = "aaaa", then it works fine! What am I
> doing wrong here?


Ok, looking closer this looks like your fault, not Python's:

Please read http://python.org/doc/current/ref/try.html

which states for the first parameter of the except clause:

"""Note that the object identities must match, i.e. it must be the same
object, not just an object with the same value."""

The lesson learnt is to *not* use string exceptions. String exceptions
are terrible outdated and quite frankly suck. If you want to create a
custom exception, subclass Exception and catch this class.

-- Gerhard

 
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
inter vlan routing - What am I doing wrong? Joel M. Baldwin Cisco 0 12-15-2004 02:47 AM
PIX setting up multiple static routes what am I doing wrong? newb Cisco 1 09-10-2004 09:07 PM
What am I doing wrong when using "use strict" ? ed Perl 1 01-05-2004 01:22 PM
VB6/VB.Net Programming Question - what am i doing wrong? Salisha Khan ASP .Net 1 08-01-2003 01:55 PM
What am I doing wrong? Keith R. Williams VHDL 4 07-15-2003 03:08 AM



Advertisments