[Tutor] Server Error

Ms Soo Chong s4046441 at student.uq.edu.au
Mon Aug 23 06:46:26 CEST 2004


Hi,

Danny, do you mean that I should replaced this:

###################################################
class BadTemplateException(Exception):
    def __str__(self):
        return "There was a problem with the HTML
template."

###################################################

with these:

 BadTemplateException = "There was a problem with
the HTML 
> template."
>    SubResult = re.subn("<!--***INSERT CONTENT
HERE***--",
>                        Content, TemplateInput)
>    if SubResult[1] == 0:
>        raise BadTemplateException

###################################################

When I replaced, a syntax error appeared:

File "<stdin>", line 33
     def__str__(self):
                     ^

SyntaxError: invalid syntax

Sorry, I don't understand the syntax error. Please
advise me.

Shufen
 

----- Original Message -----
From: Danny Yoo <dyoo at hkn.eecs.berkeley.edu>
Date: Sunday, August 22, 2004 5:07 pm
Subject: Re: [Tutor] Server Error

> Here's what it says when I run it through your
program (with the
> SyntaxErrors from our previous email all fixed up):
> 
> ###
> volado:~ dyoo$ pychecker basic4.py
> Processing basic4...
> 
> Warnings...
> 
> basic4.py:36: Raising string exceptions are deprecated
> (BadTemplateException)
> ###
> 
> 'pychecker' is reporting the use of string
exceptions here:
> 
> ###
>    # This defines an exception string in case
>    # our template file is messed up.
>    BadTemplateException = "There was a problem
with the HTML 
> template."
>    SubResult = re.subn("<!--***INSERT CONTENT
HERE***--",
>                        Content, TemplateInput)
>    if SubResult[1] == 0:
>        raise BadTemplateException
> ###
> 
> 
> Raising strings as exceptions isn't really kosher;
ancient versions of
> Python supported this, which is probably the only
reason they're still
> supported.  But use a class definition instead,
like this:
> 
> ###
> class BadTemplateException(Exception):
>    def __str__(self):
>        return "There was a problem with the HTML
template."
> ###
> 
> 
> See:
> 
>    
>
http://www.python.org/doc/tut/node10.html#SECTION0010500000000000000000
> for more information on User Defined Exceptions.
> 
> 
> Good luck!
> 
> 



More information about the Tutor mailing list