0

Given a class named DataStream

class DataStream(object):
    def __init__(self):
        self.start = start
        self.input_val = input_val

and a class named InDataStream:

class  InDataStream(DataStream):
    def __init__(self):
        super( InDataStream, self).__init__()
        self.ready = ready

stream = InDataStream()

I want to send DataStream part of stream into a function, something like:

function(stream.DataStream)

Is there any nice way to do this task?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
vikram9866
  • 91
  • 4
  • 1
    That doesn't make any sense, `stream` (or any `InDataStream`) doesn't *have a* `DataStream`, it **is a** `DataStream`. – jonrsharpe Jun 10 '16 at 22:15
  • 1
    Are you asking how to sort of downcast `InDataStream` to a `DataStream` and hide its `InDataStream` qualities? Why do you want to do this? This sounds like an [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) – rrauenza Jun 10 '16 at 22:20
  • I kind of want to use `indatastream` like a `datastream` by neglecting its `ready` attribute. I want to send indatastream's datastream part into a function. – vikram9866 Jun 11 '16 at 21:36

1 Answers1

0

If you're looking to access an instance of DataStream from an instance of class InDataStream, then you may consider using composition instead of inheritance:

class InDataStream(object):
    def __init__(self):
        self.ready = ready
        self.datastream = DataStream()

Then you can do:

stream = InDataStream()
function(stream.datastream)
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Moses Koledoye
  • 77,341
  • 8
  • 133
  • 139