Python - Printing and Classes
<p>I've read more posts and documentation on <code>__str__</code> and <code>__repr__</code> than is healthy, consulted various texts, and still cannot resolve this printing issue, so I'm putting this out there. </p>

<p>Below is a function I'd like to test.  The code isn't mine, but I would like to know how exactly it works.  I need to see a human-friendly printout of the results (i.e., no hex), so that I can play with it and generally, well, learn something because I truly have no clue how it's doing what it's doing. </p>

<pre><code>def get_ordered_adoption_center_list(adopter, list_of_adoption_centers):
    """
    The method returns a list of an organized adoption_center such that the scores for each AdoptionCenter to the Adopter will be ordered from highest score to lowest score.
    """
    list_of_adoption_centers.sort(key=lambda center:center.name)
    list_of_adoption_centers.sort(key=lambda center:adopter.get_score(center), reverse=True)
    return list_of_adoption_centers
</code></pre>

<p>Below is a relevant cross-section of code that it draws upon, which I did write.</p>

<pre><code>import random
import string

class AdoptionCenter:
    """
    The AdoptionCenter class stores the important information that a
    client would need to know about, such as the different numbers of
    species stored, the location, and the name. It also has a method to adopt a pet.
    """
    def __init__(self, name, species_types, location):
        self.name = name
        self.species_types = species_types
        self.location = (float(location[0]), float(location[1]))
    def get_number_of_species(self, species):
        return self.species_types.get(species, 0)
    def get_location(self):
        return self.location
    def get_species_count(self):
        return self.species_types.copy()
    def get_name(self):
        return self.name
    def adopt_pet(self, species):
        self.species_types[species] = self.species_types[species] - 1
        if self.species_types[species] &lt;= 0:
            del self.species_types[species]
    def __str__(self):
        return "%s" % (self.name)



class Adopter:
    """ 
    Adopters represent people interested in adopting a species.
    They have a desired species type that they want, and their score is
    simply the number of species that the shelter has of that species.
    """
    def __init__(self, name, desired_species):
        self.name = name
        self.desired_species = desired_species
    def get_name(self):
        return self.name 
    def get_desired_species(self):
        return self.desired_species
    def get_score(self, adoption_center):
        num_desired = adoption_center.get_number_of_species(self.desired_species)
        score = float(1 * num_desired)
        return score
    def __str__(self):
        return "%s and score is %d" % (self.name, self.get_score)


class FlexibleAdopter(Adopter):
    """
    A FlexibleAdopter still has one type of species that they desire,
    but they are also alright with considering other types of species.
    considered_species is a list containing the other species the adopter will consider
    Their score should be 1x their desired species + .3x all of their desired species
    """
    def __init__(self, name, desired_species, considered_species):
        Adopter.__init__(self, name, desired_species)
        self.considered_species = considered_species
    def get_score(self, adoption_center):
        num_Other = 0
        for animal in self.considered_species:
            if adoption_center.get_number_of_species(animal) &gt; 0:
                num_Other += adoption_center.get_number_of_species(animal)
        adopter_score = Adopter.get_score(self, adoption_center)
        score = adopter_score + 0.3 * num_Other
        return score
    def __str__(self):
        return "%s and score is %d" % (self.name, self.get_score)


class FearfulAdopter(Adopter):
    """
    A FearfulAdopter is afraid of a particular species of animal.
    If the adoption center has one or more of those animals in it, they will
    be a bit more reluctant to go there due to the presence of the feared species.
    Their score should be 1x number of desired species - .3x the number of feared species
    """
    def __init__(self, name, desired_species, feared_species):
        Adopter.__init__(self, name, desired_species)
        self.feared_species = feared_species
    def get_score(self, adoption_center):
        num_feared = adoption_center.get_number_of_species(self.feared_species)
        adopter_score = Adopter.get_score(self, adoption_center)
        score = adopter_score - (0.3 * num_feared)
        return max(0.0, score)
    def __str__(self):
        return "%s and score is %d" % (self.name, self.get_score)


class AllergicAdopter(Adopter):
    """
    An AllergicAdopter is extremely allergic to a one or more species and cannot
    even be around it a little bit! If the adoption center contains one or more of
    these animals, they will not go there.
    Score should be 0 if the center contains any of the animals, or 1x number of desired animals if not
    """
    def __init__(self, name, desired_species, allergic_species):
        Adopter.__init__(self, name, desired_species)
        self.allergic_species = allergic_species
    def get_score(self, adoption_center):
        for animal in self.allergic_species:
            if animal in adoption_center.get_species_count().keys():
                return 0.0
        return 1.0 * adoption_center.get_number_of_species(self.desired_species)
    def __str__(self):
        return "%s and score is %d" % (self.name, self.get_score)
</code></pre>

<p>I've tried placing <code>__str__</code> and <code>__repr__</code> methods in the various classes.  What I've read suggests <code>__str__</code> is what I'm after.  I've also tried placing a simple "for loop" with a print statement in the function body itself. This latter approach lead to a screen full of errors. I've printed using <code>__str__</code> before with success, but everything seems to be failing me on this one. Any insight would be appreciated. </p>