Building CLI applications

Our focus from the initial script example in Chapter 1, Getting Started, was on using CLI scripting to learn Python basics. CLI applications have a number of common features:

  • They often read from the standard input file, write to a standard output file, and produce logs or errors in the standard error file. The OS assures us that these files are always available. Python provides them as sys.stdin, sys.stdout, and sys.stderr. Furthermore, functions such as input() and print() use these files by default.
  • They often use environment variables for configuration. These values are available through os.environ.
  • They may also rely on shell features, like expanding ~ into a user's home directory, something done by os.path.expanduser() ...

Get Python Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.