method within class is not callable within that class?
<p>If I have a file, foo.py with contents:</p>

<pre><code>import pandas as pd

class Marcher(object):
    def __init__(self, p_path):
        self.p_path = p_path

    p_m = 'ID'

    def first_call(self):
        df_p = pd.read_csv(self.p_path, header=None)
        return df_p

    def p_to_i(self, p):
        pii = p.set_index(self.p_m, drop=False).loc[p[self.p_m]]
        return pii

    m1 = p_to_i(first_call())
</code></pre>

<p>What I would like to do with this is something like this:</p>

<pre><code>test = Marcher(p_path='/some/path/to/file.csv')
test.m1
</code></pre>

<p>However when I try this I get back an error:</p>

<pre><code>TypeError: first_call() takes exactly 1 argument (0 given)
</code></pre>

<p>The issue is you're trying to call the methods before creating an instance. Take for instance a simple Circle class:</p>

<pre><code>import math

class Circle(object):
    def __init__(self, radius):
        self.radius = radius
    def get_area(self):
        return math.pi * self.radius ** 2
    # You cannot do this because every circle can have a different radius
    # area = get_area()

    # But you can use a property
    @property
    def area(self):
        return self.get_area()

print Circle(2).area
# 12.5663706144
print Circle(10).area
# 314.159265359
</code></pre>

<p>Also, sometimes people like to cache property values to avoid re-computing them, that looks something like this:</p>

<pre><code>class Circle(object):
    # ...
    _area = None
    @property area(self):
        if self._area is None:
            self._area = self.get_area()
        return self._area
</code></pre>

<p>The downside to this method is that <code>Circle</code> is no longer a dynamic object, you should not update the "radius" attribute once the instance is created because the area is cached and will not get updated.</p>

python