TypeError: unsubscriptable object
Laszlo Nagy
gandalf at designaproduct.biz
Fri Jun 9 15:16:37 EDT 2006
k.retheesh at gmail.com írta:
> I did the same,
>
> The function type is < NoneType> and the description type is <Unicode>
> so how can i print a part of this 2 output.
>
The unicode object IS subscriptable. It is a unicode string which has
characters.
The value None is not subscriptable. It probably means that you have a
NULL value in your database.
Try the following:
def nulltoemptystr(value):
if value is None:
return "<EMPTY>"
else:
return value[:10]
print template % (ID, IID, nulltoemptystr(Function), nulltoemptystr(Description),ErrorNumber, StatusCD)
You can also try to do the same in SQL. For example, this works with
FireBird, PostgreSQL and many others:
select coalesce(Function,"") as Function from TableName
instead of
select Function from TableName
But first of all, I would recommend you to go over the Python tutorial.
It explains these things and more.
http://docs.python.org/tut/tut.html
Best,
Laszlo
More information about the Python-list
mailing list