私はスクリプトの次の段階を選択するためのフィードバックをユーザに求める場所を持っています。ユーザが私の ' if-else '部分を辞書に追加します。私はどのような 'プレーン'関数を呼び出すことができますが、多くの場合、同じ関数をいくつかの引数で呼び出さなければなりませんが、既に持っているスクリプトの本体にこれらの関数を追加する方法は分かりません。辞書からの引数を使用したPythonコール関数
def runthis():
# getting user input
decide = input(str(
'Select option 1'
'Select option 2'
'Select option 3'
'Select option etc'
'Select option n'))
# each action listed here as a function without parentesis and arguments
options = {
'1': func1,
'2': func2,
'3': func3,
'etc': funcetc,
'n': funcn}
# go through the list and look for key matching user decision
# then run the value as a function - how to pass arguments when I need?
if decide in options.keys():
options[decide]()
else:
print('invalid entry')
runthis()
runthis()
おかげで、感謝任意のヘルプ:それは、この(私は問題を抱えている場所を見て、それをコメントしようとします)のように見えます。
私はそうしたに見えます最後にlution:http://stackoverflow.com/questions/24580993/calling-functions-with-parameters-using-a-dictionary-in-python – s3icc0