Sharpen Your Coding Skills with Command-Line Arguments in Python
Python is a fantastic language for scripting, prototyping, and developing portable back-end applications. The extensive libraries and multi-platform support allow you to modify, modularize, and iterate quickly. One handy technique that can save you headaches and make your systems more secure is using command-line arguments (CLAs). Often we only consider using these after the application reaches a certain level of complexity or requires a UI for release, but implementing them early can actually help you write better code and close up security holes. Let’s look at a few reasons why, and then demo some code (scroll on down to section 4 if you just want to see the ‘how’).
1. Better Design from the Beginning
If we’re just building some quick automation, or prototyping an in-house application, it’s often tempting to just hard-code parameters and resist abstraction to save time in the short-term. But time invested in design and modularity often pays huge dividends, whether you find yourself needing to refactor frequently to incorporate changes, or the time is lost to debugging as the program grows. A solid foundation always saves time.
Command line arguments are a great way to force yourself to consider what parameters you might want to specify at runtime/deployment…