O'Reilly logo

Python Essentials by Steven F. Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required