views:

33

answers:

0

I am trying to find a clever way to convert a super class into a subclass using python. Here is the situation:

class Super():
    anAttribute = ''

class Sub(Super):
    anotherAttribute = ''

I have a function which returns me a list of type Super which I need to convert to a Sub, modify slightly and pass on to the next portion of my application which requires both anAttribute and anotherAttribute.

Since Super() is defined in a library there can be no coupling between Sub() and the method that returns it.

I can think of several ideas although I am looking for something more clever:

  1. Use Methods (store a copy of the parent and override to just call out)
  2. Simply copy over the variable although that means that I will have 2 versions of the same data

This would be easy to do in C# where I could just overwrite the property methods; is there something similar in Python?