Python: issue with calling methods
<p>I'm new to Python and  I've written a class for managing a simple phonebook. (I've removed the methods that aren't relevant to this post). </p>

<pre><code>class Phonebook:

    def __init__(self):
        self.book = {}

    def newEntry(self, name, number):
        self.book[name] = number

    def findNumber(self, name):
        return self.book[name]

    def nameList(self):
        list = self.book.keys()
        list.sort()
        for k in list:
            print k, self.book[k]
</code></pre>

<p>My question concerns the last method, <code>nameList</code>, which prints the phonebook entries (name and phone no.) in alphabetical order. Originally, I tried the following:</p>

<pre><code> def nameList(self):
        list = self.book.keys()
        list.sort()
        for k in list:
            print k, findNumber(k)
</code></pre>

<p>However, this threw up a "NameError" global name 'findNumber' is not defined" error. Would someone be able to explain why this didn't work?</p>

<p>Thanks in advance.</p>
