May-15-2017, 07:36 AM
(May-15-2017, 06:18 AM)Ofnuts Wrote:(May-15-2017, 03:09 AM)Skaperen Wrote: my new class has set_opts() and get_opts(). set_opts() works from named options. get_opts() returns a dict with the options. an additional feature: set_opts() returns a dict of unrecognized options. this new class has 8 options (there are not setters or getters for individual options because of so many).
The problem with getters/setters is not code verbosity. It is that they allow inconsistent states. If you rename some "Marmaduke Skaperen" to "Alexandre-Benoit Ofnuts" with setters on first name and last name, your object can temporarily be set to "Marmaduke Ofnuts" or "Alexandre-Benoit Skaperen".
but ... should i change this part of my code?
def get_opts(self): return { 'gutter': self.gutter, 'width': self.width, 'height': self.height, 'height2': self.height2, 'top': self.top, 'left': self.left, 'right': self.right, 'bottom': self.bottom, }
def set_opts(self,**opts): for o in option_names_all: if o in opts: v = opts.pop(o) if v != None: setattr(self,'_'+o,v) return opts
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.