Note that @shiracamus told me that when the number of functions increases, it will be easier to manage if you put the functions in a dictionary and make them commands.
https://qiita.com/mochihisa/items/2bb433636c4c615b0961#comment-f5565d1700921d4edc9f
Give the function pointer a name like a function table.
You can see the convenience compared to this article (self-deprecation) Manage functions in a list
├── modules
│ └──logic.py
│
└─ main.py
modules/logic.py
def func1(word):
print('Here func1' + word)
def func2(word):
print('Here func2' + word)
def func3(word):
print('Here func3' + word)
def func4(word):
print('Here func4' + word)
def func5(word):
print('Here func5' + word)
def help_command():
print("""\
func1 ----Call func1
func2 ----Call func2
func3 ----Call func3
func4 ----Call func4
func5 ----Call func5
""")
COMMANDS = {
"func1": func1,
"func2": func2,
"func3": func3,
"func4": func4,
"func5": func5,
}
main.py
import modules.logic as logic
logic.help_command()
logic.COMMANDS['func1']('is')
logic.COMMANDS['func2']('Yade')
logic.COMMANDS['func3']('That'sright')
logic.COMMANDS['func4']('Nyoro')
logic.COMMANDS['func5']('Daje')
$ python main.py
func1 ----Call func1
func2 ----Call func2
func3 ----Call func3
func4 ----Call func4
func5 ----Call func5
This is func1
This is func2
This is func3
This is func4
This is func5
Recommended Posts