Python & Music: Performance question

David Asorey Álvarez forodejazz at yahoo.es
Sun Apr 6 06:18:50 EDT 2003


Hello, group.

I'm developing a small music program, and I have some doubts.

   I want define a class, Note, which represents a note. It has two
attributes, pitch and duration (quarter note, half note, etc). There
will be a lot of instances of this object, maybe hundreds of notes,
and the program needs access to all of this objects and read its
attributes.
   Which implementation will be more efficient?

Implementation A:

class Note:
   def __init__(self, pitch, duration):
      self.pitch = pitch
      self.duration = duration
   def change_pitch(factor): pass
   def change_duration(factor): pass
   # more methods ...

Implementation B:

class Note:
   def __init__(self, pitch, duration):
      self["pitch"] = pitch
      self["duration"] = duration
   def change_pitch(factor): pass
   def change_duration(factor): pass
   # more methods ...

Regards.

David.

P.S.: Excuse my poor English!




More information about the Python-list mailing list