#๐Ÿ”’ class atrabute cant be set

26 messages ยท Page 1 of 1 (latest)

opal quest
#

i have an attribute that will never change, it always reads 0

charred turtleBOT
#

@opal quest

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

cunning skiff
#

class atrabute
Is it a class attribute or instance attribute? If you have a class attribute and try to assign it on self, the debugger might be getting confused.

#

What's the whole class definition? @opal quest

opal quest
#

wait i think its len

cunning skiff
#

So that's not the case.

self.wtf = 1 will definitely assign the value 1 to self.wtf, so I'd double check that the value isn't be reassigned elsewhere.

cunning skiff
opal quest
#

that should never get called tho. welp ill investigate some more

cunning skiff
#

Well, there's two other places self.wtf is assigned. I'd put prints at each place.

Also, I don't see where it would happen here, but note that __len__ is called if you don't define __bool__ and you try to treat the object as a boolean value.

opal quest
#

ITS THE DEBUGER

#

the debuger calls __len__ every code step

cunning skiff
#

I'm not sure why it would do that. It shouldn't need to query the length, unless it does that to show a length in the watch panel or something.

Out of curiosity, if you define __bool__ on the class, does it stop calling __len__?

#

Wait, now I'm confused:

opal quest
cunning skiff
#

Wait, ya, I was right, it's for the watch panel:

#

It tries to see if the class defines a length so it can show it

#

T: 5, where 5 is the length

opal quest
cunning skiff
#

I got bit by a similar bug where I had a custom list class that defined a __str__ method. I created a massive instance of the list, then the debugger insisted on calling str on it constantly and bogged down the debugging.

opal quest
#

debuger becomes a rebugger

cunning skiff
#

THe circle of life

steady marsh
#

debugger doing its job -> ui ruined it

charred turtleBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.