[Tutor] object does not support item assignment

Mats Wichmann mats at wichmann.us
Mon Jul 19 13:28:27 EDT 2021


On 7/19/21 10:22 AM, Dennis Lee Bieber wrote:
> On Mon, 19 Jul 2021 12:54:07 +1000, Phil <phillor9 at gmail.com> declaimed the
> following:
> 
> 
>> class Led:
>>          self.led = Led((50, 50))
> 
> 	How many Led classes do you have defined. To me, that assignment is
> just creating another instance of the very class you have defined, and the
> __init__() of that instance will define another instance, ad infinitum.

what's more, because of the way Python evaluates things, at the time 
that line runs Led won't be defined yet, so you'll get a NameError. The 
class definition has to be fully executed before Python stores the 
object reference as the name Led.





More information about the Tutor mailing list