files and exceptions/exceptions/examples/exceptions.py
def count_words(filename):
    """Count the approximate number of words in a file."""
    try:
        with open(filename) as file:
            contents = file.read()
    except FileNotFoundError as error_type:
        msg = "Sorry, the file " + filename + " does not exist."
        print(msg)
    else:
        # Count approximate number of words in the file.
        words = contents.split()
        num_words = len(words)
        print("The file " + filename + " has about " + str(num_words) + " words.")
Count the approximate number of words in a file.
Count the approximate number of words in a file.
Count the approximate number of words in a file .
def count_words(filename):
    try:
        with open(filename) as file:
            contents = file.read()
    except FileNotFoundError as error_type:
        msg = "Sorry, the file " + filename + " does not exist."
        print(msg)
    else:
        words = contents.split()
        num_words = len(words)
        print("The file " + filename + " has about " + str(num_words) + " words.")
def count_words ( filename ) : try : with open ( filename ) as file : contents = file . read ( ) except FileNotFoundError as error_type : msg = "Sorry, the file " + filename + " does not exist." print ( msg ) else : words = contents . split ( ) num_words = len ( words ) print ( "The file " + filename + " has about " + str ( num_words ) + " words." )
Count the approximate number of words in a file.
Count the approximate number of words in a file .
"""Count the approximate number of words in a file.""" # Count approximate number of words in the file.

filename