How to do it...

  1. Check whether the input is a password or something equally subject to redaction. If so, then use the getpass.getpass() function. This means we need to import the following function:
        from getpass import getpass 

Otherwise, if the redacted input is not required, use the input() function.

  1. Determine which prompt will be used. This might be as simple as >>> or something more complex. In some cases, we might provide a great deal of contextual information. In our example, we provided a field name and a hint about the type of data expected as a prompt string. The prompt string is the argument to the input() or getpass() function:
        year = int(input("year: ")) 
  1. Determine how to validate each item in isolation. The simplest case ...

Get Modern Python Cookbook 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.