Save and Load data in Python 3
<p>I have to create a team roster that saves and loads the data. I have it to the point where everything else works but saving and loading.</p>

<pre><code>memberList = []
#get first menu selection from user and store in control value variable
def __init__(self, name, phone, number):
    self.__name = name
    self.__phone = phone
    self.__number = number
def setName(self, name):
    self.__name = name
def setPhone(self, phone):
    self.__phone = phone
def setnumber(self, number):
    self.__number = number
def getName(self):
    return self.__name
def getPhone(self):
    return self.__phone
def getNumber(self):
    return self.__number
def displayData(self):
    print("")
    print("Player's Information")
    print("-------------------")
    print("Player's Name:", getName)
    print("Player's Telephone number:", getPhone)
    print("Player's Jersey number:", getNumber)
def displayMenu():
    print("==========Main Menu==========")
    print("1. Display Team Roster")
    print("2. Add Member")
    print("3. Remove Member")
    print("4. Edit Member")
    print("9. Exit Program")
    print()
    return int(input("Selection&gt;"))
menuSelection = displayMenu()
def printMembers(memberList):
    print("Current members: ")
    if len(memberList) == 0:
        print("No current members in memory.")
    else:
        x = 1
        while x &lt; len(memberList):
            print(memberList[x],)
            x = x + 1
def addPlayer(memberList): # players as an argument
    newName = input("Add a player's Name: ")
    newPhone = input("Telephone number: ")
    newNumber = input("Jersey number: ")
    memberList.append(newName)
    return memberList
def removePlayer(memberList):
    removeName = input("What name would you like to remove? ", )
    # Don't redefine it!
    if removeName in memberList:
        del memberList[removeName]
    else:
        print("Sorry", removeName, "was not found!")
    return memberList
def editPlayer(memberList):
    oldName = input("What name would you like to change? ", )
    if oldName in memberList:
        newName = input("What is the new name? ")
        print("***", oldName, "has been changed to", newName)
    else:
        print("***Sorry", oldName, "was not found!")
    return memberList
def saveData(memberList):
    filename=input("Filename to save: ", )
    print("saving data...")
    outfile=open(filename, "wt")
    filename= '/Users\nativ\ Documents'
    for x in memberList:
        name = memberList[x].getName()
        phone = memberList[x].getPhone()
        number = memberList[x].getNumber()
        outfile.write("name","age", 'number')
    print("Data Saved")
    outfile.close()
def loadData():
    filename = input("Filename to load: ")
    inFile = open(filename, "rt")
def exitProgram(memberList):
    print("Exiting Program...")
while menuSelection != 9:
    if menuSelection == 1:
        printMembers = printMembers(memberList)
        menuSelection = displayMenu()
    elif menuSelection == 2:
        memberList = addPlayer(memberList)
        menuSelection = displayMenu()
    elif menuSelection == 3:
        memberList = removePlayer(memberList)
        menuSelection = displayMenu()
    elif menuSelection == 4:
        memberList = editPlayer(memberList)
        menuSelection = displayMenu()
    elif menuSelection == 5:
        memberList = saveData(memberList)
        menuSelection = displayMenu()
    elif menuSelection == 6:
        memberList = loadData()
    menuSelection = displayMenu()
print('Welcome to the Team Manager')
displayMenu()
</code></pre>

<p>This is the error code that I am getting</p>

<pre><code>Traceback (most recent call last):
  File "C:/Users/nativ/PycharmProjects/Week2/Week 5.py", line 98, in &lt;module&gt;
    memberList = saveData(memberList)
  File "C:/Users/nativ/PycharmProjects/Week2/Week 5.py", line 73, in saveData
    name = memberList[x].getName()
TypeError: list indices must be integers or slices, not str
</code></pre>

<p>Try <code>name = memberList[int(x)].getName()</code>. When it reads the data from a file it reads a string, and in order to put that into a list you need to make it an integer.</p>

python file save load