Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion generators as decorators simple issue
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
j.m.dagenh...@gmail.com  
View profile  
 More options Sep 11 2012, 10:28 pm
Newsgroups: comp.lang.python
From: j.m.dagenh...@gmail.com
Date: Tue, 11 Sep 2012 19:28:10 -0700 (PDT)
Local: Tues, Sep 11 2012 10:28 pm
Subject: generators as decorators simple issue
I'm trying to call SetName on an object to prevent me from ever having to call it explictly again on that object. Best explained by example.

def setname(cls):
    '''this is the proposed generator to call SetName on the object'''
    try:
        cls.SetName(cls.__name__)
    finally:
        yield cls

class Trial:
    '''class to demonstrate with'''
    def SetName(self, name):
        print 1, 1

@setname
class Test(Trial):
    '''i want SetName to be called by using setname as a decorator'''
    def __init__(self):

        print 'Yay! or Invalid.'

if __name__ == '__main__':
    test = Test()

How can i fix this?
This is my exact error: python decors2.py
Traceback (most recent call last):
  File "decors2.py", line 23, in <module>
    test = Test()
TypeError: 'generator' object is not callable


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.