Python 3 - Cant get data to display when called
<p>This is the function defined in class "Roster"</p>

<pre><code>class Roster:
    def __init__(self, name, phone, jersy):
        self.name = name
        self.phone = phone
        self.jersy = jersy
    def setName(self, name):
        self.name = name
    def setPhone(self, phone):
        self.phone = phone
    def setnumber(self, jersy):
        self.number = jersy
    def getName(self):
        return self.name
    def getPhone(self):
        return self.phone
    def getNumber(self):
        return self.jersy
    def displayMenu(self):
        print ("==========Selection Menu==========")
        print ("1. Display the Roster")
        print ("2. Add a Player to the Roster")
        print ("3. Remove a Player from the Roster")
        print ("4. Change a Player Name displayed in the Roster")
        print ("5. Load the Roster")
        print ("6. Save the Roster")
        print ("7. Quit")
        print ()
        return int (input ("Selection&gt;&gt;&gt;  "))
    def displayRoster(self):
        print ("****Team Roster****")
        print ("Player's Name:", self.name)
        print ("Player's Telephone number:", self.phone)
        print ("Player's Jersey number:", self.jersy)
</code></pre>

<p>This is the code:( I understand that you don't have to "Import" a class into itself so there is no Import call)</p>

<pre><code>Players = {}

def addPlayer(Players):
    newName = input ("Add a player's Name: ")
    newPhone = input ("Phone number: ")
    newNumber = input ("Jersey number: ")
    Players[newName] = newName, newPhone, newNumber
    return Players


def removePlayer(Players):
    removeName = input ("What name would you like to remove? ")
    if removeName in Players:
        del Players[removeName]
    else:
        print ("Name was not found!")
    return Players


def editPlayer(Players):
    oldName = input ("What name would you like to change? ")
    if oldName in Players:
        newName = input ("What is the new name? ")
        newPhone = input ("Phone number: ")
        newNumber = input ("Jersey number: ")
        Players[newName] = newName, newPhone, newNumber
        del Players[oldName]
        print ("***", oldName, "has been changed to", newName)
    else:
        print ("Name was not found!")
    return Players

def saveRoster(Players):
    print("Saving data...")
    outFile = open("D:\Documents\Grantham\Python Projects\Python Week Six\Roster.txt", "wt")
    for x in Players.keys():
        name = Roster.getName(Players)
        phone = Roster.getPhone(Players)
        jersy = Roster.getNumber(Players)
    outFile.write("name+","+phone+","+jersy+","\n")
    print("Data saved.")
    outFile.close()
    return Players

def loadRoster():
    Players = {}
    filename = input("Filename to load: ")
    inFile = open(Filename(Players), "rt")
    print("Loading data...")
    while True:
        inLine = inFile.readline()
        if not inLine:
            break
    inLine = inLine[:-1]
    name, phone, jersy = inLine.split(",")
    Players[name] = RosterClass.Players(name, phone, jersy)
    print("Data Loaded Successfully.")
    inFile.close()
    return Players

print ("Welcome to the Team Manager")
menuSelection = Roster.displayMenu ('Players')
while menuSelection != 7:
    if menuSelection == 1:
        myRoster.displayRoster (Players)
    elif menuSelection == 2:
        Players = addPlayer (Players)
    elif menuSelection == 3:
        Players = removePlayer (Players)
    elif menuSelection == 4:
        Players = editPlayer (Players)
    elif menuSelection==5:
        loadRoster(Players)
    elif menuSelection==6:
        saveRoster(Players)
    menuSelection = Roster.displayMenu (Players)
print ("Exiting Program...")
</code></pre>

<p>I keep getting this error:</p>

<pre><code>Traceback (most recent call last):
  File ".idea/Adv Team Roster.py", line 108, in &lt;module&gt;
    Roster.displayRoster ('Players')
  File ".idea/Adv Team Roster.py", line 39, in displayRoster
    print ("Player's Name:", self.name)
AttributeError: 'str' object has no attribute 'name'
</code></pre>

<p>I'm also having problems with the save/load routine but that's another post.</p>

<p>Your code has a number of conceptual problems that you need to solve before you can start trying to run it and start asking for help with compiler errors. Here are three, to get you started.</p>

<p>(1) Your <code>Roster</code> class is designed to be instantiated, but you never create an instance. Whenever you write a class, among the early questions you should ask yourself are, "What code will create instances of this class? Under what circumstances? How will that code get the data it needs to create an instance? What will that code do with the instance right after it has created the instance?" </p>

<p>(2) Your <code>Roster</code> class is misnamed, which is probably confusing you. A roster is a list of players. Your <code>Roster</code> is data about a single player. I recommend renaming <code>Roster</code> to <code>Player</code>, creating some data structure (like your current <code>Players</code>) called <code>roster</code> to hold a bunch of players, and then following the consequences of that change.</p>

<p>(3) Once you have a clear idea of what rosters and players are, you can ask questions like, "Where will I store rosters and players? How will I pass them around to different parts of my code? What functionality should be associated with a roster? with a player? with the top level of my code? with other entities that I haven't thought about yet?"</p>

<p>After all that thinking, you might come the conclusion that <code>displayPlayer</code> should be a function on the <code>Player</code> class and that you therefore need to rename <code>displayRoster</code> to <code>displayPlayer</code>. Since you will have created instances of Player, perhaps one called myplayer (that's just an example name), you will now be able to say <code>myplayer.displayPlayer()</code>, and Python will run the <code>displayPlayer</code> code with <code>self</code> automatically set to the myplayer instance. At that point the compiler error you are complaining about will disappear, not because you "fixed" it, but because it naturally goes away once you are thinking clearly about your system.</p>

<p>And in general, that is the way to think about compiler errors: If it's not immediately obvious how to fix it, then it's probably a sign that you aren't thinking clearly about your system, so you need to take a step back and think about higher-level problems than the specific error.</p>

python attributeerror