En Fri, 13 Mar 2009 17:12:49 -0200, alex goretoy <aleksandr.gore...@gmail.com> escribió:

wow, ok, thank you Gabriel, I wasn't aware of x,'y',z

This is what I decided to go with for now in one of my classes, but another
class will need a modified version of this, as mentioned x,'y',z

        B=_brush()

list( ( self.__setattr__(x.replace("b_",""),getattr(B,x)) for x in
dir(B) if x.startswith("b_") ) )

__special__ methods are an implementation detail that you should not use explicitely; instead of obj.__setattr__(name, value) use setattr(obj, name, value).

And building a list of None just to discard it isn't good style (that is: don't use a generator expression / list comprehension just by its side effect if you don't want the resulting list object)

So I'd write the above as:

for name in dir(B):
  if name.startswith("b_"):
    setattr(self, name[2:], getattr(B, name))

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to