Re: Decorator help

Discussion in 'Python' started by Arnaud Delobelle, Mar 27, 2013.

  1. On 27 March 2013 19:49, Joseph L. Casale <> 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
     
    Arnaud Delobelle, Mar 27, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. glomde
    Replies:
    5
    Views:
    549
    glomde
    Mar 29, 2007
  2. Vishal Shetye

    Help: Group based synchronize decorator

    Vishal Shetye, Jun 18, 2009, in forum: Python
    Replies:
    1
    Views:
    261
    Piet van Oostrum
    Jun 19, 2009
  3. Michele Simionato
    Replies:
    1
    Views:
    294
    Michele Simionato
    May 25, 2010
  4. Joseph L. Casale

    Decorator help

    Joseph L. Casale, Mar 27, 2013, in forum: Python
    Replies:
    4
    Views:
    192
    Joseph L. Casale
    Mar 31, 2013
  5. Jason Swails

    Re: Decorator help

    Jason Swails, Mar 27, 2013, in forum: Python
    Replies:
    2
    Views:
    173
    88888 Dihedral
    Mar 31, 2013
Loading...

Share This Page