ODBC error trap resolved! Now...

Paul Boddie paulb at infercor.no
Fri Apr 28 12:40:37 CEST 2000


"Daley, MarkX" wrote:
> 
> OK, so the error trapping is good, but now I run into an append problem.  I
> have a list defined in the beginning of the function, like so:
> 
> servername = ['ServerA', 'ServerB', 'ServerC']
> for index in servername:
>         try:
>                 #Big routine to collect and write data to a file.
>         except dbi.opError:

This should really be 'ODBC.something.OperationalError' or
'module.OperationalError'.

>                 servername.append(index)
> 
> So, if one of the servers doesn't make the connection, it gets added to the
> end of the list until it does connect.  This worked great in my test
> scripts, but when put to practice, I get this:
> 
> Traceback (innermost last):
>   File "<pyshell#1>", line 1, in ?
>     collect.collect()
>   File "C:\PROGRA~1\Python\collect.py", line 51, in collect
>     servername.append(index)
> AttributeError: 'string' object has no attribute 'append'

It looks like 'servername' has been made to refer to a string value. Since
strings can be treated like other sequence objects, you may be getting single
character strings assigned to 'index' in the loop as well.

> I didn't see this when I tested my append function.  What do I not
> understand about lists in this context?

It looks like an incorrect assignment has happened somewhere, but it is hard to
tell from what you have written. If the above suggestion doesn't help, perhaps
you could provide a bit more detail.

Paul



More information about the Python-list mailing list