String argument -> name of list?

Gustaf Liljegren gustafl at algonet.se
Sat Nov 3 11:56:32 EST 2001


I'm making a program for training musical scales. It should for example be 
able to ask things like: "What is the name of the sixth chord in the F# 
Phrygian scale?".

I have a list of scale names that looks like this:

# Scale names
scales = [
  'ionian',
  'dorian',
  'phrygian',
  'lydian',
  'mixolydian',
  'aeolian',
  'locrian'
]

There's also a list for each of these scales, so that the program can 
calculate how a scale looks, based on the chromatic scale and a root key.

# Modal scale structures
ionian     = [0, 2, 2, 1, 2, 2, 2]
dorian     = [0, 2, 1, 2, 2, 2, 1]
phrygian   = [0, 1, 2, 2, 2, 1, 2]
lydian     = [0, 2, 2, 2, 1, 2, 2]
mixolydian = [0, 2, 2, 1, 2, 2, 1]
aeolian    = [0, 2, 1, 2, 2, 1, 2]
locrian    = [0, 1, 2, 2, 1, 2, 2]

The program chooses one of the scales randomly, so I may get for example 
the string 'dorian' in one session and the string 'locrian' in the next.

Finally, there's a function that should take any of the lists of scale 
structures as an argument. Or perhaps it's better if it takes a string 
value, but it's currently taking the list. Anyway I choose, the problem is 
to make the conversion from a string ('ionian') to the list name (ionian) 
to get the scale structure.

I wonder if it is any simple syntax for converting a string to the name of 
a list? Or should I use another structure instead, like a dictionary with 
strings + lists, or a list with strings + lists?

Gustaf



More information about the Python-list mailing list