Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Anatomy of a Command Line Interface

00:00 In this lesson, I’ll talk to you about what building a command line interface in any programming language actually entails.

00:08 Because a command line interface is built to always take in some kind of input from a user, the programmer has to do a little bit more work to deal with things like parsing and validation. When you read a command line interface, you first have to verify the argument structure to see whether it fits the standards that you as the programmer have designed for that command line interface.

00:30 This is what you normally do with parsing: determine the contents, the order, deal with things like mutual exclusivity, and so on. Then, you should normally be checking for some kind of type validation. In Python, this is a bit nebulous because Python is not a super strongly typed programming language already, but you do have to check whether all of the arguments have the correct type at least to some basic level, right?

00:52 All of the arguments that are supposed to be numbers have to be parseable as numbers, you know? If you had an argument that was supposed to be a number and someone just put in "cat", it wouldn’t be clear at all what that was supposed to mean as a number.

01:03 You have to do some form of type validation. And then, finally, you have to do behavioral validation, and this is something that you should be doing in really any well-written Python program, anyway. This is stuff like checking whether filenames are actually valid files, or whether things that are supposed to be a member of an enumerative set are actually members of that set as opposed to being some random input. And then, of course, after all of this comes the real logic of your actual program that you’re supposed to run with the command line interface. Over the next few lessons, I’ll show you several different ways that you can implement parsing for your command line interface, and then I’ll also show you a little bit about type validation.

01:44 The behavioral validation is something that I’ll cover more incidentally as I go through the various code files: how to handle things like FileNotFoundError, or set membership problems, or something like that.

Become a Member to join the conversation.