运行以下课程时,我得到NameError: name 'self' is not defined
。发生了什么,我该如何解决?
class Tuner():
def __init__(self, key=-1, notelist=[[0, 4]]):
"""
Takes a list of 2-element lists containing a note and its 8ve,
then finds the equal-tempered frequency of each note,
appending this frequency to a new list 'freqlist'
"""
#if key != -1:
key = inputkey()
print key
#if notelist != [[0, 4]]:
notelist = inputnotes()
freqs_equal = []
for note in notelist:
letter = note[0]
octave = note[1]
freq = 440 * ((2 ** (1.0/12.0)) ** (letter - 9 - (12 * 4)))
if octave != 0:
freq = freq * ((2 ** (1.0/12.0)) ** (octave * 12))
freqs_equal.append(freq)
freqs_just = []
for note in notelist:
letter = note[0]
octave = note[1] # get the note's name and octave
if letter - key >= 0:
interval = letter - key
else:
interval = (letter + 12) - key
octave -= 1
keyfreq = 440 * ((2 ** (1.0/12.0)) ** (key - 9 - (12 * 4)))
letterfreq = keyfreq * justratios[interval]
letterfreq = letterfreq * (2 ** octave)
freqs_just.append(letterfreq)
self.freqs_equal = freqs_equal
self.freqs_just = freqs_just