(The following is python3-related (if that matter).)
This this the code I've written (simplified) :
class MyClass: def __init__(self): self.__some_var = [] @property def some_var(self): return self.__some__var @some_var.setter def some_var(self, new_value): if hasattr(new_value, '__iter__'): self.__some_var = new_value else: self.__some_var.append(new_value)
I want to replace when setting if their is several "values" (i.e if new_value is an iterable of, in my case, non-iterable objects) and appending if their is only one "value". I'm concerned about the performance of hasattr so I wonder if I shouldn't use this setter instead :
@some_var.setter def some_var(self, *args): if len(args) > 1: self.__some_var = args else: self.__some_var.append(args)
Thank for your attention !