The object locations are how the objects are printed out. Strictly speaking, calling str or repr on a list calls repr on each element on the list. By default, repr(team) on a Teams object will return something like <main.Teams object at 0x02953230>. You can override that by defining a __repr__ method on the Teams class. However, this doesn't sound like what you want here.
If TeamList is a list of Teams objects, and you want to turn it into a list of their TeamName members, you just use a list comprehension to convert it:
TeamNameList = [team.TeamName for team in TeamList]
Note that this still isn't going to be exactly you want to print out:
>>> print TeamNameList
['North Carolina', 'South Carolina', 'West Carolina', 'East Carolina', 'Underground Carolina', 'Cloud-level Carolina', 'Past Carolina', 'Future Carolina'] # those are all states, right?
You probably want something like this:
>>> print ', '.join(TeamNameList)
North Carolina, South Carolina, West Carolina, East Carolina, Underground Carolina, Cloud-level Carolina, Past Carolina, Future Carolina
From your comments:
there is a later function simGame(teamA, Teamb)
I see the instances, however I am not sure how to call them in the second function. I had planned on calling them by name. In the example I gave, North_carolina can be passed to the later (not shown function) and calculations can be run on the data
I think I understand what you want here. You want to be able to simulate a game between North Carolina and South Carolina, when all you have is the TeamList.
To do that, you probably want to create a dict, mapping the names to the Teams objects, like this:
TeamDict = {team.TeamName: team for team in TeamList}
Now, you can do things like this:
simGame(TeamDict['North Carolina'], TeamDict['South Carolina'])
Now, simGame is going to get the North Carolina and South Carolina instances of the Teams class as its teamA and teamB arguments, so it can do things like:
def simGame(teamA, teamB):
scoreA = int(teamA.FT * 1 * 20) + int(teamA.FG * 2 * 40) + int(teamA.Three * 3 * 10)
scoreB = int(teamB.FT * 1 * 20) + int(teamB.FG * 2 * 40) + int(teamB.Three * 3 * 10)
if scoreA > scoreB:
print 'Home team {} beats visitor {} by {}!'.format(teamA.TeamName,
teamB.TeamName,
scoreA - scoreB)
else:
print 'Visitors {} win by {} over {} at home!'.format(teamB.TeamName,
scoreB - scoreA,
teamA.TeamName)
Is that what you want?
Some additional comments:
You can also do the same thing as the list comprehension using map, which avoids having to write team twice, but it also means you can't use normal expression syntax:
TeamNameList = map(operator.attrgetter('TeamName'), TeamList)
Or you can use map together with lambda to get back the expression syntax back… and the repeat of team:
TeamNameList = map(lambda team: team.teamName, TeamList)
But for cases like this, the list comprehension is generally considered the pythonic way to do it. (Also, it doesn't change if you go to Python 3, whereas map changes from a list to an iterator, which means print TeamNameList will give you something like <builtins.map at 0x108022350>… But ', '.join(TeamNameList) will still work.)
As a side note, in standard (PEP 8) Python style, usually only classes are in TitleCase like this, and variables and attributes are in lower_case. If you really like CamelCase, you can get away with lowerFirstCamelCase, but using TitleCase will throw off people reading your code, who will immediately try to figure out where the TeamName class is defined. Also see the comments from bvukelic.
As another side note, you seem to be doing a lot of repeated code, and I'm not sure why:
name = info[0]
FT = info[1]
FG = info[2]
Three = info[3]
newTeam = (name, FT, FG, Three)
You're just copying info to newTeam; why add all those intermediate variables that never get used again?
newTeam2 = Teams(newTeam[0],newTeam[1],newTeam[2],newTeam[3])
You could replace all of that with just:
newTeam2 = Teams(info[0],info[1],newTeam[2],newTeam[3])
Or even:
newTeam2 = Teams(*info)
If you have a need for the separate variables somewhere that you haven't shown us, that's fine, but you still can't possibly need newTeam; just do this:
newTeam2 = Teams(name, FT, FG, Three)
print Teamlistto print. Do you want a comma-separated list of all of the team names, or a newline-separated list of (a comma-separated list of all of the team properties) for each team, or …? If I've guessed wrong in my answer, please clarify exactly what your expected output is.