[Tutor] TypeError: unsubscriptable object

Rilindo Foster webmaster at monzell.com
Wed Sep 3 22:51:30 CEST 2008


As it turns out, I messed up. TotalStoreSales  was returning as a  
integer, not a list. Which lead me to other issues with the script in  
question.

Doh!

Sorry about that and thanks!

On Sep 3, 2008, at 4:37 PM, Kent Johnson wrote:

> On Wed, Sep 3, 2008 at 3:44 PM, Rilindo Foster  
> <webmaster at monzell.com> wrote:
>> Hi! Long time reader, first time poster (I think).
>>
>> I am trying to do a comparison on a particular list item. The list in
>> question comes in this pair:
>>
>> TotalStoreSales = Revenues + "," + Orders
>> TotalStoreSales = TotalStoreSales.split(",")
>
> These two lines could be just
> TotalStoreSales = [Revenues, Orders]
>
>> At this point, it has two values, both strings.
>>
>> Then I attempt to do a comparison like so:
>>
>> if (float(TotalStoreSales[0]) > 0):
>>   (does stuff)
>>
>> I know that it is converting into a float - that I verified.
>>
>> At any event, it keeps returning with this:
>>
>> Traceback (most recent call last):
>> File "./getMivaStoreTransactions.py", line 143, in ?
>>   TotalSales = TotalSales + getStoreStats(d[0],AllSales)
>> File "./getMivaStoreTransactions.py", line 120, in getStoreStats
>>   if (float(TotalStoreSales[0]) > 0):
>> TypeError: unsubscriptable object
>>
>> Maybe I am missing something someplace. Help?
>
> Is anything else happening between these two snippets? Try putting
>  print type(TotalStoreSales), TotalStoreSales
> before the if statement.
>
> Kent

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080903/9137f56d/attachment.htm>


More information about the Tutor mailing list