Python interpreter error: unsupported operand type(s) for -: 'tuple' and 'int'

George Yoshida ml at dynkin.com
Tue Mar 29 23:09:58 EST 2005


Rakesh wrote:

 > To quote a much smaller trimmed-down example, here is how it looks
 > like:
 > ## -----------------------------------------------
 > # Entry Point to the whole program
 > ## -----------------------------------------------
 > def main():
 >     mylist = GenerateList()
 >     minnumber = min(mylist)
 >     for num in mylist:
 >         print num - minnumber
 >         ## TODO: Interpreter errors above.


Try printing mylist. Then you'll know why - operand doesn't work.
You're creating a nested tuple.

I'd recommend changing the original script to something like::

   seconds = []
   [snip]

       # Convert the date format to the seconds since epoch
       for i in xrange( len(dates) ):
           thissecond = parseDate(dates[i][1])
           seconds.append(thissecond)

or if you want to stick with tuple::

   seconds = ()
   [snip]

       # Convert the date format to the seconds since epoch
       for i in xrange( len(dates) ):
           thissecond = parseDate(dates[i][1])
           seconds += (thissecond, )

-- george



More information about the Python-list mailing list