Question : Calling a python method from a class

I've tried reading the python docs on classes, objects and data models but I still don't get it - I suppose that advanced programmers need to write classes but for what I'm able to do, writing a class seems to make things more difficult than they need to be.

I'm trying to write a program that requires me to create an instance of a 'Dog' class with the dog's name and breed as arguments, and append the object to the dogs list. For each user input on the name and breed, the current dogs list should print the name and breed of each dog, example:
#DOGS
0. Snoopy:Beagle
1. Marmaduke:Great Dane
2. Rover:Mutt

I can't figure out how to call the function so I'm not sure if the problem is with the way I'm trying to call the function or the way that I've written the methods in the class. Some of the guidance was fairly specific, for example the init() method should take two parameters, name and breed, in addition to the implicit self.  

I've copied the errors below with the offending code, and I don't understand the errors (if I did, I suppose I could fix this).
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
class Dog:

    def __init__(self, name, breed):
        self.name = 'Dog Name'
        self.breed = 'Dog Breed'
        self.dog_list = []

    # because 'dogs' in add_dog(**dogs) turned out to be undefined,  
    # not sure why...
    def keywords_as_dict(**dogs):
        return dogs
       
    def add_dog(**dogs):
	while True:
            try:
                name = raw_input("Enter dog name: ")
                breed = raw_input("Enter dog breed: ")

    		for name, breed in dogs.items():
            	    my_dog = (name.capitalize() + ": " + breed.capitalize())
                    print(my_dog)
                    dog_list.append(my_dog)
	    
	    except name == '':
                print('Exiting program')

        return dogs, dog_list
                           
if __name__ == "__main__":
    zero = Dog(name='Lassie', breed='Retriever') # or 
    one = Dog('Lassie', 'Retriever')
    print(zero, one) 
    # prints <__main__.Dog instance at some hex code> for each
    Dog.add_dog(one) # type error, method takes 0 args 
    Dog.add_dog() # or
    Dog.add_dog('Goofy', 'mutt') # or 
    Dog.add_dog(name='Goofy', breed='mutt') # type errors,
    # unbound methods must be called with class instance as first argument

Answer : Calling a python method from a class

Line 8 doesn't create a "Dog"

instead of:

my_dog = (name.capitalize() + ": " + breed.capitalize())

You need something like:

my_dog = Dog( name.capitalize(), breed.capitalize() );

How about something like:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
class Dog() :
  def __init__( self, name, breed ) :
    self.name = name;
    self.breed = breed;
  def getName( self ) :
    return self.name;
  def getBreed( self ) :
    return self.breed;

if __name__ == '__main__' :
  kennel = [];             # Create an empty list of dogs
  while True :
    name = raw_input( ' Name: ' ).strip();
    if name :
      breed = raw_input( 'Breed: ' ).strip();
      if breed :
        kennel.append( Dog( name.capitalize(), breed.capitalize() ) );
    else :
      break;
  print '\nDogs:\n' + ( '-' * 40 );
  for i in range( len( kennel ) ) :
    dog = kennel[ i ];
    print '%d. %s:%s' % ( i, dog.getName(), dog.getBreed() );

else :
  print "Error - execute this script, don't import it.\n";
  print 'python %s.py' % __name__;
Random Solutions  
 
programming4us programming4us