Confusion over how to share and modify class level data between instances.
<p>I don't understand how 'static' class data works in Python. I'm attempting to replicate a pattern I used often in Java where I create a central faux-database class, and give instances of it to any classes that need it. </p>

<p>However, here's where I'm lost with Python, it seems like anytime I try to access the 'static' variable, I create an instance level one. It's very confusing. </p>

<p>Here's the code: </p>

<pre><code>import csv 

class Database(object):
    data = list()
    def __init__(self):
        pass

    def connect(self, location=None):
        path = '.\\resources\\database\\'
        with open(path + 'info.csv', 'rU') as f:
            csv_data = csv.reader(f, delimiter=',')
            for row in csv_data:
                self.data.append(Entry(*row))
</code></pre>

<p>As you can see, pretty straight forward. I declare <code>data</code> outside of the <code>init</code>, which I believe makes it class level. I then loop through a csv file and append each row's cell fields to the <code>data</code> list. </p>

<p>Here's where I get confused. The first thing I wanted to do was slice of the first entry in the <code>data</code> list (this just had the column named from the excel sheet). But in doing this, it seems to create an instance level version of <code>data</code> rather than modifying the class level <code>data</code> that I want.</p>

<p>So, I modified the code as follows</p>

<pre><code>import csv 

class Database(object):
    data = list()
    def __init__(self):
        pass

    def connect(self, location=None):
        path = '.\\resources\\database\\'
        with open(path + 'info.csv', 'rU') as f:
            csv_data = csv.reader(f, delimiter=',')
            for row in csv_data:
                self.data.append(Entry(*row))
            self.data = self.data[1:]  ## &lt;--- NEW LINE HERE
</code></pre>

<p>As you can see, I tried to slice it as I would any other list, but in doing so, it makes (seemingly) a local version of <code>data</code></p>

<p>In my <code>main()</code>, I have the following code to test out some of the attributes:</p>

<pre><code>def main():
    settings = Settings()

    db = csv_loader.Database()
    db.connect(settings.database)
    print 'gui.py:', db.data[0].num
    print 'gui.py:', db.data[0].name
    print 'gui.py:', len(db.data)
</code></pre>

<p>This behaves just as expected. It has 143 entries, because of the previous slice operation. </p>

<p>Now, I have another class which has an instance of <code>Database()</code> <em>but</em> the slice had no effect. </p>

<pre><code>self.db = Database()
self.settings = Settings()
print 'tabOne.py:', self.db.data[0].conf_num
print 'tabOne.py:', self.db.data[0].conf_name
print len(self.db.data)
</code></pre>

<p>The printout from this class shows that there are 144 elements in the list -- so the slice operation didn't actually modify the class level <code>data</code>. </p>

<p>What am I missing? Am I attempting to modify the class level variable incorrectly or something? </p>
