Discussion:
TypeError: unsubscriptable object
k.retheesh
2006-06-09 18:38:40 UTC
Permalink
So wat should I do ??
print template % (ID, IID, Function[:10], Description[:10],
ErrorNumber, StatusCD)
TypeError: unsubscriptable object
It means either 'Function' or 'Description' is not a sequence.
Try inserting print statements to see what values they are.
a = 2
a[:10]
will give me an 'unsubscriptable object'
Regards
Sreeram
--------------enig08E562E3E8ED90BF5BC3C92B
Content-Type: application/pgp-signature
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename="signature.asc"
Content-Description: OpenPGP digital signature
X-Google-AttachSize: 253
Diez B. Roggisch
2006-06-11 14:47:26 UTC
Permalink
Can anybody tell me why am I getting this error message while trying to
print a part of a string. Is there a better approach for this...
Because you don't use a string? The error message is pretty clear:

TypeError: unsubscriptable object

So - what are Function[:10], Description[:10] ? You _assume_ they are
strings, seems not to be the case.

Diez
k.retheesh
2006-06-09 17:38:46 UTC
Permalink
Can anybody tell me why am I getting this error message while trying to
print a part of a string. Is there a better approach for this...

Traceback (most recent call last):
File
"C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
line 310, in RunScript
exec codeObject in __main__.__dict__
File "Q:\PythonScripts\InventoryCompareCase.py", line 276, in ?
main()
File "Q:\PythonScripts\InventoryCompareCase.py", line 167, in main
print template % (ID, IID, Function[:10], Description[:10],
ErrorNumber, StatusCD)
TypeError: unsubscriptable object

Thanks
Retheesh
k.retheesh
2006-06-09 18:38:51 UTC
Permalink
So wat should I do ??
print template % (ID, IID, Function[:10], Description[:10],
ErrorNumber, StatusCD)
TypeError: unsubscriptable object
It means either 'Function' or 'Description' is not a sequence.
Try inserting print statements to see what values they are.
a = 2
a[:10]
will give me an 'unsubscriptable object'
Regards
Sreeram
--------------enig08E562E3E8ED90BF5BC3C92B
Content-Type: application/pgp-signature
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename="signature.asc"
Content-Description: OpenPGP digital signature
X-Google-AttachSize: 253
k.retheesh
2006-06-09 18:52:30 UTC
Permalink
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.

These values are returned by database.

Thanks
Retheesh
Post by k.retheesh
So wat should I do ??
print type(Function),type(Description)
raise SystemExit
print template % (ID, IID, Function[:10], Description[:10],ErrorNumber, StatusCD)
<type 'int'> <type 'int'>
instead of
<type 'str'> <type 'str'>
or something similar. (Of course in your case, it can be 'float instead of list' or 'dictionary instead of tuple' etc.)
Then you should debug your program and find out why the 'Function' and 'Description' objects are not string but int.
Laszlo
Laszlo Nagy
2006-06-09 19:16:37 UTC
Permalink
Post by k.retheesh
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
k.retheesh
2006-06-09 19:27:26 UTC
Permalink
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.

These values are returned by database.

Thanks
Retheesh
Post by k.retheesh
So wat should I do ??
print type(Function),type(Description)
raise SystemExit
print template % (ID, IID, Function[:10], Description[:10],ErrorNumber, StatusCD)
<type 'int'> <type 'int'>
instead of
<type 'str'> <type 'str'>
or something similar. (Of course in your case, it can be 'float instead of list' or 'dictionary instead of tuple' etc.)
Then you should debug your program and find out why the 'Function' and 'Description' objects are not string but int.
Laszlo
Laszlo Nagy
2006-06-09 18:47:17 UTC
Permalink
Post by k.retheesh
So wat should I do ??
You should do this:

print type(Function),type(Description)
raise SystemExit

Instead of this:

print template % (ID, IID, Function[:10], Description[:10],ErrorNumber, StatusCD)

Then probably you will see:

<type 'int'> <type 'int'>

instead of

<type 'str'> <type 'str'>


or something similar. (Of course in your case, it can be 'float instead of list' or 'dictionary instead of tuple' etc.)

Then you should debug your program and find out why the 'Function' and 'Description' objects are not string but int.


Laszlo

k.retheesh
2006-06-09 18:50:02 UTC
Permalink
So wat should I do ??
print template % (ID, IID, Function[:10], Description[:10],
ErrorNumber, StatusCD)
TypeError: unsubscriptable object
It means either 'Function' or 'Description' is not a sequence.
Try inserting print statements to see what values they are.
a = 2
a[:10]
will give me an 'unsubscriptable object'
Regards
Sreeram
--------------enig08E562E3E8ED90BF5BC3C92B
Content-Type: application/pgp-signature
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename="signature.asc"
Content-Description: OpenPGP digital signature
X-Google-AttachSize: 253
K.S.Sreeram
2006-06-09 17:47:06 UTC
Permalink
print template % (ID, IID, Function[:10], Description[:10],
ErrorNumber, StatusCD)
TypeError: unsubscriptable object
It means either 'Function' or 'Description' is not a sequence.
Try inserting print statements to see what values they are.

e.g:

a = 2
a[:10]

will give me an 'unsubscriptable object'

Regards
Sreeram

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 260 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20060609/b16fd9f8/attachment.pgp>
Loading...