Creating an object from a base class object in Python
<p>I have a base class:</p>

<pre><code>class Animal(object):
    def __init__(self, name=None, food=None):
        self.name = name
        self.food = food

    def eat(self):
        print "The %s eats some %s" % (self.name, self.food)
</code></pre>

<p>And a class that extends it:</p>

<pre><code>class Pet(Animal):
    def pet(self):
        print "You pet the %s." % self.name
    def feed(self):
        print "You put some %s into the bowl." % self.food
        self.eat()
</code></pre>

<p>Let's say I have an <code>Animal</code> object, created thusly:</p>

<pre><code>&gt;&gt;&gt; fluffy_as_animal = Animal('dog', 'kibbles')
</code></pre>

<p>Is there a straightforward way in python to create a <code>Pet</code> object from <code>fluffy_as_animal</code>, short of actually writing out:</p>

<pre><code>&gt;&gt;&gt;&gt; fluffy_as_pet = Pet(fluffy_as_animal.name, fluffy_as_animal.food)
</code></pre>

<h1>Update</h1>

<p>The reason I'm doing this implementation is that I have a class with a function that returns a set of objects of type <code>Animal</code> all which I want to actually use as <code>Pet</code> objects:</p>

<pre><code>class AnimalStore(object):
    def fetch(count, query=None, server=None, *args, **kwargs):
        connection = connect_to_server(server)
        resp = connection.fetch_animals(query)
        objects = parse_response(resp)
        animals = []
        for a in objects[:count]:
            animals.append(Animal(a['name'], a.['food']))
        return animals

class PetStore(AnimalStore):
    def fetch(count, query=None, server=None, *args, **kwargs):
        query = 'type=pet AND %s' % query
        animals = super(PetFactory, self).fetch(count, query, server, *args, **kwargs)
        pets = []
        for animal in animals:
            pets.append(magic_function(animal))
        return pets
</code></pre>

<p><code>AnimalStore</code> and <code>PetStore</code> are in separate modules. <code>AnimalStore</code> is part of a standard <code>Animal</code> API and doesn't change. Basically I want to extend the <code>Animal</code> API by fetching a list of pets using the same mechanism used for animals, and I want to be able to take advantage of all of the other built-in functions that the Animal API already provides for its <code>Animal</code> and <code>AnimalStore</code> classes.</p>
