avatar Bite 357. Implement your First Subcommands and Command Groups

In the previous Bite, you learned how to create an application and added several commands for that app.

Now, let's create some subcommands to further organize your application, see the subcommands documentation.

Create a subcommand "algorithm" from which further subcommands "sum", "subtract", ... can be run as following:

$ python script.py algo sum
$ python script.py algo substract

We already reorganized the code for you into algorithms.py and comparison.py, which both contain the function and command definitions from the previous exercise.

Note: Due to the how the platform works with AWS Lambda, mentioned modules will be downloaded and added to /tmp which is being appended to sys.path so they can be imported.

All you need to do is to add the applications (Typer app instances) from algorithms.py and comparison.py into a single application using the app.add_typer() method.

Enjoy!

 

Login and get coding
go back Beginner level
Bitecoin 2X

26 out of 28 users completed this Bite.
Will you be Pythonista #27 to crack this Bite?
Resolution time: ~37 min. (avg. submissions of 5-240 min.)

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help