[Tutor] Creating a class and calling an exception

Becky Mcquilling ladymcse2000 at gmail.com
Fri Jun 3 22:36:12 CEST 2011


Thank you very much.  I should have added that I did that and it ran. I had
one other error in the script thta I missed.  I fixed that and it ran, then
I named them as recommended and it still works and fits better with
conventions, so I learned two things.


On Fri, Jun 3, 2011 at 1:05 AM, Alan Gauld <alan.gauld at btinternet.com>wrote:

>
> "Becky Mcquilling" <ladymcse2000 at gmail.com> wrote
>
>  The Second script written here, always raises the exception and I'm
>> missing
>> why, any advice?
>> class Log_Parser:
>>   def __init__(self):
>>       self.re_backup_status = re.compile(r'^\s+Files\s+:\s+\d',
>> re.IGNORECASE)
>>
>>   def log_parse(self, log_file):
>>
>>     try:
>> ....
>>
>>           for line in log1:
>>             if re_backup_status.search(line):
>>
>
> When accessing an attribute of a class you need to prefix with self.
> You are getting a name error here I suspect.
>
>
>        log1.close()
>>     except:  print "%s" %('succeeded:0 failed:10000')
>>
>
> But your cattchall exception is hiding the error. If you add
> a raise inside the exception handler while debugging it
> will print the full error text.
>
> If you did that you would have been pointed to the
> line with the error and told the name of the bad name.
> Using a catchall exceptioon is OK after the code is
> working if you want to shield your users from tracebacks,
> but during debugging catchall exceptions are evil,
> don't do it.
>
> HTH,
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110603/e274a737/attachment-0001.html>


More information about the Tutor mailing list