Make a Runnable Script
00:13 Then it will try to find the maze’s solutions and render them in separate tabs in your web browser as scalable vector graphics. If it can’t find any solutions, then you’ll see an appropriate message in your console.
It uses the
argparse module to parse the file path, which is currently the only expected command-line argument. Later, you can add more if you want to—for example, to allow previewing mazes without a solution. Finally, the file uses the name-main idiom to protect the
main() function from running if other modules import the package.
Optionally, you can specify a shortcut in your
pyproject.toml file. You can have as many custom commands as you like, which should map to specific functions in the given module within the project.
Note that you need to run it from your virtual environment. The
solve command, which you just created, is not available outside of it. You now have a working command-line interface to your Python package and a working maze solver that you can access quickly from the command line or terminal. While you’ve reached the end of this two-part course, remember that you can always keep improving the project. For example, you could add more command-line arguments to control the rendering process or provide an option to save the results as an image instead of previewing them in the browser. The possibilities are endless, but in the next part of the course, you’ll look back at what you’ve learned.
Become a Member to join the conversation.