Let's say there is a library function called get_pack() which returns a Pack object:
class Pack(object):
def __init__(self, name, weight):
self.name = name
self.weight = weight
...
What I want to do is to wrap this object into my object which is let's say CommercialPack which has a couple of useful functions:
class CommercialPack(Pack):
def get_delivery_price(self, distance):
return self.weight * PER_KM_PRICE * distance
...
And then create a function which returns CommercialPack instead of Pack. In some other languages like Delphi or Java, you can type cast that object on the fly. So I want to have something like:
def get_commercial_pack():
return CommercialPack(get_pack())
and then you have all you need with no hassle. Because I would like my CommercialPack object to have all the properties and functions that Pack object has. I just want to wrap it inside my new class. Basically I don't want to do something like this:
class CommercialPack(object):
def __init__(self, pack):
self.name = pack.name
self.weight = pack.weight
...
OR
class CommercialPack(object):
def __init__(self, pack):
self.pack = pack
I'm looking for an elegant solution instead like I said, some kind of type casting or whatever I can do elegantly in Python.
Thanks very much.