469,631 Members | 1,732 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

TypeError: unsubscriptable object

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

Jun 9 '06 #1
9 79729
k.********@gmail.com wrote:
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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEibQfrgn0plK5qqURAvU+AJwIDY3uvG5xh7O4+KnkcH jlINla2wCbBXSR
11DRLQgLy4ffXmOvntW6FNg=
=iPC6
-----END PGP SIGNATURE-----

Jun 9 '06 #2
So wat should I do ??

K.S.Sreeram wrote:
k.********@gmail.com wrote:
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
--------------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


Jun 9 '06 #3
So wat should I do ??

K.S.Sreeram wrote:
k.********@gmail.com wrote:
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
--------------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


Jun 9 '06 #4
k.********@gmail.com írta:
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

Jun 9 '06 #5
So wat should I do ??

K.S.Sreeram wrote:
k.********@gmail.com wrote:
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
--------------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


Jun 9 '06 #6
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

Laszlo Nagy wrote:
k.********@gmail.com írta:
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


Jun 9 '06 #7
k.********@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
Jun 9 '06 #8
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

Laszlo Nagy wrote:
k.********@gmail.com írta:
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


Jun 9 '06 #9
k.********@gmail.com schrieb:
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
Jun 11 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Atul Kshirsagar | last post: by
2 posts views Thread by Balaji | last post: by
reply views Thread by Luis P. Mendes | last post: by
5 posts views Thread by Randall Parker | last post: by
1 post views Thread by Gary Wessle | last post: by
10 posts views Thread by Charles Russell | last post: by
2 posts views Thread by AWasilenko | last post: by
33 posts views Thread by christophertidy | last post: by
reply views Thread by Chris Rebert | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.