How to access variables from super?
<p>I need to get at some variables in a method called with <code>super</code> I would really like to do this instead of subclassing and then redefining the method...</p>

<pre><code>class Foo(object):
    def bar(self):
        x = 1

class SubFoo(Foo):
    def bar(self):
        print x
        super(SubFoo, self).bar(*args, **kwargs)
</code></pre>

<p>but I am getting <code>object has no attribute 'request'</code></p>

<p>I tried using self as well but it would not work</p>

<p>There are two ways you can do this, either make x an instance attribute, or return x in your <code>Foo.bar</code> method. Below example makes use of assigning x as an instance attribute: </p>

<pre><code>class Foo(object):
    def bar(self):
        self.x = 1


class SubFoo(Foo):
    def bar(self):
        super(SubFoo, self).bar()
        print(self.x)


s = SubFoo()
s.bar()
</code></pre>

<p>The above execution will output <code>1</code>. </p>

<p>Alternatively, you can do a <code>return x</code> from your <code>Foo.bar</code> method, but remember, then that means you need to handle this return somehow. So, you need to make sure you get the return from your <code>super</code> call: </p>

<pre><code>    def bar(self):
        res = super(SubFoo, self).bar()
        print(res)
</code></pre>

python