0

「choice」= ii7 と「scale」= C の 2 つの変数があるとします。

このライブラリには、これを実行することにより、特定の音楽コードの音符を把握する機能があります。

chords.ii7(音階)

スケール = C の場合、C のスケールで ii7 コードのノートがリストされます。

コード自体に ii7 を含める代わりに変数「choice」を使用する必要がある場合、どうすればよいでしょうか? 何を検索するかを知っていれば、間違いなく検索がはるかに簡単になりますが、私はまったくの初心者です。これは、この特定のプログラムの残りの部分を締めくくり、何か新しいことを学ぶためのものです。タイトルの言い方が間違っていたらすみません。前もって感謝します!

4

1 に答える 1

1

Use getattr

getattr(chords, choice)(scale)

This is assuming choice = 'ii7'.

getattr basically takes two parameters - the first being an object, the second being a string. It searches for an attribute that has the same name as the string, and returns it. In this case getattr(chords, choice) returns chords.ii7, which you then have to call.

于 2013-01-29T04:13:50.623 に答える