'AttributeError:' when I try to unpickle dictionary
<p>I have made a program on python 3.5 which you can find out the password linked to a username, make a new password for an existing user and add a new user and password to the dictionary then pickles it so every time I load the program all the usernames and passwords will be there.</p>

<p>The error that comes up is after you create the pickle file(after running it for the first time) then on line 6 the error</p>

<pre><code>AttributeError: Can't get attribute 'NewPass' on &lt;module '__main__' (built-in)&gt;
</code></pre>

<p>occurs.</p>

<p>Here is my script:</p>

<pre><code>import sys
import pickle
import os

if os.path.exists("branston.p"):
    LOGG = pickle.load(open('branston.p', 'rb'))

else:
    LOGG = {'Sam': ('CHRIST')}

def Find():
    Username = input("Say a Username.")
    print (LOGG[Username])

def NewPass():
    Username = Input("Enter your username.")

    Newpass = input("Enter your new password")

    if NewPass == input("Confirm password"):
        LOGG[Username] = (NewPass)

def NewEntry():

    NewUser = input("Enter your new username.")
    Newpass = input("Enter your new password.")

    LOGG[NewUser] = (NewPass)

loop = True

while loop == True:

    function = input("Say what you want me to do.'Find', 'NewPass', 'NewEntry', 'Stop'.")

    if function == ("Find"):
        Find()

    elif function == ("NewPass"):
        NewPass()

    elif function == ("NewEntry"):
        NewEntry()

    elif function == ("Stop"):
        f = open('branston.p', 'wb')
        pickle.dump(LOGG, f)

        f.close()
        sys.exit()
</code></pre>

<p>Any help would be appreciated. Thanks!</p>

<p>When you do this</p>

<pre><code>LOGG[NewUser] = (NewPass)
</code></pre>

<p>You are assigning the function <code>NewPass</code> to your dict entry. You are probably intending to assign the password string and therefore it should be.</p>

<pre><code>LOGG[NewUser] = Newpass
</code></pre>

<p>Note: Parenthesis are superfluous. I'd also suggest avoiding using upper case letters as the first character of your variable names, as otherwise it is easy to confuse variable and function names.</p>

python python-3.x dictionary pickle