Forum Archive

Music Scale Generator

craigmrock

Hi,
Getting an error that “mode object has no attribute scale_steps” when I run this, but I think everything is ok. Does anyone see where there is a disconnect??
```
legal_mode = [
"Ionian",
"Dorian",
"Phrygian",
"Lydian",
"Mixolydian",
"Aeolian",
"Locrian"]
stepping = [2, 2, 1, 2, 2, 2, 1]
major_mode = ["Ionian"]

class Mode():
def init(self,title):
self.title = title
self.ismajor = title in major_mode
tonic = legal_mode.index(title)
self.stepping = stepping[tonic:]+stepping[:tonic]

    def __str__(self):
        return "Title: {}, Major{}".format(self.title, self.ismajor)

    def scale_steps(self):
        return "Half-steps{}".format(''.join(str(c) for c in self.stepping))

mode1 = Mode("Ionian")
print(mode1)
print(mode1.scale_steps())

mode2 = Mode("Dorian")
print(mode2)
print(mode2.scale_steps())```

cvp

@craigmrock Shift left the two def str and scale_steps, they are inside init

legal_mode = [ 
    "Ionian", 
    "Dorian",
    "Phrygian",
    "Lydian",
    "Mixolydian",
    "Aeolian",
    "Locrian"]
stepping = [2, 2, 1, 2, 2, 2, 1]
major_mode = ["Ionian"]

class Mode():
    def __init__(self,title):
        self.title = title
        self.ismajor = title in major_mode
        tonic = legal_mode.index(title)
        self.stepping = stepping[tonic:]+stepping[:tonic]

    def __str__(self):
        return "Title: {}, Major{}".format(self.title, self.ismajor)

    def scale_steps(self):
        return "Half-steps{}".format(''.join(str(c) for c in self.stepping))

mode1 = Mode("Ionian")
print(mode1)
print(mode1.scale_steps())

mode2 = Mode("Dorian")
print(mode2)
print(mode2.scale_steps())