#๐ Property is logging I don't have attribute in class, but operates properly?
15 messages ยท Page 1 of 1 (latest)
@limpid osprey
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.
I am wondering if there is a problem with how my classes getter/setters are opperating at the moment. Currently I am getting the error
self.sort(column = column, remove_sort=True)
File "B:\Python Projects\DPT Calculator\Afterdark-Damage-Calculator\scripts\my_tkinter.py", line 87, in sort
self.previous_sort(column, data_type, reverse, callback, FALSE)
^^^^^^^^^^^^^^^^^^
File "B:\Python Projects\DPT Calculator\Afterdark-Damage-Calculator\scripts\my_tkinter.py", line 94, in previous_sort
if self._previous_sort is not None:
^^^^^^^^^^^^^^^^^^^
AttributeError: 'MyTreeview' object has no attribute '_previous_sort'. Did you mean: 'previous_sort'?```
The link to the entier class code can be found here, but the property getter/setter is defined here:
@property
def previous_sort(self):
if self._previous_sort is not None:
self._previous_sort = self.previous_sort(ignore_sort = True)
return self._previous_sort
@previous_sort.setter
def previous_sort(self, column : str = "#0", data_type : type = str, reverse : bool = False, callback = None, ignore_sort : bool = False):
self._previous_sort = {"column" : column, "data_type" : data_type, "reverse" : reverse, "callback" : callback, "ignore_sort" : ignore_sort}```
I am currently working on documenting/refactoring the code, and was intending for this to make it more legible.
The code seems to be operating correctly when running, and is not having problems at the moment, however it is populating the console quite a bit, and I'm not sure If i am secretly stabbing myself in the foot and making life harder.
well, is it meant to be a function or a property? you are trying to (recursively) call it like a function ```py
def previous_sort(self):
...
... self.previous_sort(ignore_sort = True)
also you'll have to define it within __init__ if you want to default to None
...also that setter makes no sense? setters are used for instance.property = value, they only receive a single argument
!e ```py
class Foo:
def init(self):
self._val = 0
@property
def val(self):
return self._val
@val.setter
def val(self, new_value):
self._val = new_value
foo = Foo()
print(foo.val)
foo.val = 2
print(foo.val)
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | 0
002 | 2
I have been learning about getter/setters recently, and have been having a bit of trouble wrapping my head around them. I was attempting to make it a public variable that I can use while checking if there was a previous_sort, or if the entry is empty to set it to a defualt.
You do bring up a good point about defining the default inside the __init__ method, and I will try that.
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.
๐ Property is logging I don't have attribute in class, but operates properly?