[Tutor] object does not support item assignment

Phil phillor9 at gmail.com
Sun Jul 18 22:54:07 EDT 2021


I'm in the process of converting a C++ programme that I wrote some time 
ago to Python but I've run into a problem at an early stage.

The following is a snippet of the code.

One Led works but how do I work with 8 Leds? led1 =, led2 =, etc and 
then add them to a list? That might be OK for 8 Leds but I think there 
must be a better way.

TypeError: 'Led' object does not support item assignment

class Led:
     def __init__(self, pos):
         self.pos = pos

         self.led = Led((50, 50))

         for i in range(8):
             self.led[i] = Led((50, 50))

-- 

Regards,
Phil



More information about the Tutor mailing list