unsubscriptable object error
Tim Golden
tim.golden at viacom-outdoor.co.uk
Thu Aug 18 08:03:47 EDT 2005
[MCollins at seminolecountyfl.gov]
> getting an unsubscriptable object error on an if else statement
> db = MSSQL.connect(server,login,pwd,database)
> c = db.cursor()
> c.execute(mySQL)
> rows = c.fetchone()
> #determine recipient
> if str(rows[3]) == str(rows[4]):
> recipient = str(rows[0]) + " " + str(rows[1])
> else:
> recipient = "test"
> the above code works fine if rows[3] == rows[4]. it's when it doesn't equal that it gives the error::
> TypeError: unsubscriptable object
> args = ('unsubscriptable object',)
Hi, Matthew.
Couple of points first: if it's possible, try to send emails in plain-text
only, no HTML or Rich-Text. Makes life easier in some viewers. (And this
list is gatewayed to news:comp.lang.python and to Google Groups).
Also, try to screen dump the *actual* traceback, not your
copy of it. Your example is self-contained so I imagine it
can easily be run at the interpreter. (Which may be what
you're doing).
Finally, I suspect that your (slightly ill-named) "rows" is getting
a None back from c.fetchone (). Consider the following example:
<code>
import MSSQL
# substitute your own connection info
db = MSSQL.connect ("VODEV1", "", "", "EVODEV")
c = db.cursor ()
c.execute ("SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE 1 = 2")
# guaranteed no rows
rows = c.fetchone ()
print rows
# will display 'None'
print rows[3], rows[4]
# will display unsubscriptable object
</code>
I realise that you say "the above code works find if
rows[3] == rows[4]" but how do you know? If I've got the
wrong end of the stick, can you publish a working snippet
which can reproduce the error?
TJG
________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
More information about the Python-list
mailing list