Inheritance problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mr.SpOOn

    Inheritance problem

    Hi,
    I have a problem with this piece of code:


    class NoteSet(Ordered Set):
    def has_pitch(self) :
    pass
    def has_note(self):
    pass

    class Scale(NoteSet):
    def __init__(self, root, type):
    self.append(roo t)
    self.type = type
    ScaleType(scale =self)

    OrderedSet is an external to use ordered sets. And it has an append
    method to append elements to the set.

    When I try to create a Scale object:

    s = Scale(n, '1234567') # n is a note

    I get this error:

    Traceback (most recent call last):
    File "notes.py", line 276, in <module>
    s = Scale(n, '1234567')
    File "notes.py", line 243, in __init__
    self.append(roo t)
    File "ordered_set.py ", line 78, in append
    self._insertatn ode(self._end.p rev, element)
    AttributeError: 'Scale' object has no attribute '_end'

    I can't understand where the error is.
    Can you help me?

    Thanks,
    Carlo
  • Diez B. Roggisch

    #2
    Re: Inheritance problem

    Mr.SpOOn wrote:
    Hi,
    I have a problem with this piece of code:
    >
    >
    class NoteSet(Ordered Set):
    def has_pitch(self) :
    pass
    def has_note(self):
    pass
    >
    class Scale(NoteSet):
    def __init__(self, root, type):
    self.append(roo t)
    self.type = type
    ScaleType(scale =self)
    >
    OrderedSet is an external to use ordered sets. And it has an append
    method to append elements to the set.
    >
    When I try to create a Scale object:
    >
    s = Scale(n, '1234567') # n is a note
    >
    I get this error:
    >
    Traceback (most recent call last):
    File "notes.py", line 276, in <module>
    s = Scale(n, '1234567')
    File "notes.py", line 243, in __init__
    self.append(roo t)
    File "ordered_set.py ", line 78, in append
    self._insertatn ode(self._end.p rev, element)
    AttributeError: 'Scale' object has no attribute '_end'
    >
    I can't understand where the error is.
    Can you help me?
    You need to call the __init__ of NoteSet inside Scale, as otherwise the
    instance isn't properly initialized.

    class Scale(NoteSet):
    def __init__(self, root, type):
    super(Scale, self).__init__( )
    ...

    or
    NoteSet.__init_ _(self)

    if you have an old-style class.

    Diez

    Comment

    • Mr.SpOOn

      #3
      Re: Inheritance problem

      On Wed, Nov 5, 2008 at 6:59 PM, Diez B. Roggisch <deets@nospam.w eb.dewrote:
      You need to call the __init__ of NoteSet inside Scale, as otherwise the
      instance isn't properly initialized.
      Thanks, solved.

      Comment

      Working...