Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #42036

Decorator help

From "Joseph L. Casale" <jcasale@activenetwerx.com>
Subject Decorator help
Date 2013-03-27 19:49 +0000
Newsgroups comp.lang.python
Message-ID <mailman.3824.1364413867.2939.python-list@python.org> (permalink)

Show all headers | View raw


I have a class which sets up some class vars, then several methods that are passed in data
and do work referencing the class vars.


I want to decorate these methods, the decorator needs access to the class vars, so I thought
about making the decorator its own class and allowing it to accept args.


I was hoping to do all the work on in_data from within the decorator, which requires access
to several MyClass vars. Not clear on the syntax/usage with this approach here, any guidance
would be greatly appreciated!


Class MyDecorator(object):

    def __init__(self, arg1, arg2):
        self.arg1 = arg1
        self.arg2 = arg2
    ...


Class MyClass(object):
    def __init__(self):
        self.var_a = ....
    ....
    @MyDecorator(...)
    def meth_one(self, in_data):
        ...


Thanks!
jlc

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Decorator help "Joseph L. Casale" <jcasale@activenetwerx.com> - 2013-03-27 19:49 +0000
  Re: Decorator help Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-27 23:29 +0000
    Re: Decorator help Jason Swails <jason.swails@gmail.com> - 2013-03-27 22:38 -0400
      Re: Decorator help Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-28 04:58 +0000
    RE: Decorator help "Joseph L. Casale" <jcasale@activenetwerx.com> - 2013-03-31 00:06 +0000

csiph-web