function decorators to specify the first two lines of the def?
<p>I'm on python 3.5:</p>

<p>I have a repeating pattern in some of my python functions. For a large collection of classes the first two lines are:</p>

<pre><code>obj_a = &lt;..... obtain something I need.....&gt;
obj_b = &lt;..... obtain another thing I need....&gt;
</code></pre>

<p>I'm simplifying it here, but the process of obtaining <code>obj_a</code> and <code>obj_b</code> isn't a one liner... I would like to avoid repeating this code anywhere in a more elegant way than a util function to obtain <code>obj_a</code> and <code>obj_b</code> (e.g. <code>obj_a = getObjectA()</code>...) </p>

<p>Is there any way to take those lines and put them as part of a decorator of a function where I have something like:</p>

<pre><code>@function_where_I_need_my_objects
def foo:
  &lt;....do something with obj_a and obj_b already initialized....&gt;
</code></pre>

<p>You can put those two objects in a base class as:</p>

<pre><code>class TheBaseClass:
    obj1 = something
    obj2 = something_else
</code></pre>

<p>and inherit this in the functions of classes you need:</p>

<pre><code>class Class1(TheBaseClass):
    def func1(self):
       a = self.obj1  # make use of it
       b = self.obj2  # make use of it
</code></pre>

python python-3.x