Decorator help

Arnaud Delobelle arnodel at gmail.com
Wed Mar 27 21:21:37 CET 2013


On 27 March 2013 19:49, Joseph L. Casale <jcasale at activenetwerx.com> wrote:
> 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):
>         ...

I don't really understand what you are trying to do.  It would be
easier if you had some code that tried to do something (even if it
doesn't quite work).

-- 
Arnaud



More information about the Python-list mailing list