generators as decorators simple issue
Oscar Benjamin
oscar.j.benjamin at gmail.com
Wed Sep 12 06:47:02 EDT 2012
On Wed, 12 Sep 2012 03:22:31 -0700 (PDT), pyjoshsys
<j.m.dagenhart at gmail.com> wrote:
> The output is still not what I want. Now runtime error free,
however the output is not what I desire.
> def setname(cls):
> '''this is the proposed generator to call SetName on the
object'''
> try:
> cls.SetName(cls.__name__)
> except Exception as e:
> print e
> finally:
> return cls
I would write the function above in one line:
cls.name = name
> class Trial(object):
> '''class to demonstrate with'''
> def __init__(self):
> object.__init__(self)
> self.name = None
Remove the line above. The instance attribute self.name is hiding the
class attribute cls.name.
Oscar
More information about the Python-list
mailing list