#Import dependencies
#Load OS functions from the standard library
import os

os.chdir('/home/israel/Development/Python_Exercises/python-octo-wookie/head1stpython/Chapter3')
#Change path for the current directory

data = open('sketch.txt')


#Start iteration over the text file
for each_line in data:
            try:
                (role, line_spoken) = each_line.split(':', 1)
                print(role, end = '')
                print(' said: ', end = '')
                print(line_spoken, end = '')
            except:
                pass

data.close()
        

#Import dependencies
#Load OS functions from the standard library
import os

#Change path for the current directory
os.chdir('/home/israel/Development/Python_Exercises/python-octo-wookie/head1stpython/Chapter3')

#Check if file exists
if os.path.exists('sketch.txt'):
    
    #Load the text file into 'data' variable
    data = open('sketch.txt')

    #Start iteration over the text file
    for each_line in data:
    #We use try/except to handle errors that can occur with bad input
                try:
                    (role, line_spoken) = each_line.split(':', 1)
                    print(role, end = '')
                    print(' said: ', end = '')
                    print(line_spoken, end = '')
                except:
                    pass

    #After all the iteration and printing, we close the file
    data.close()

#If file does exists, we simply quit and display an error for the user/dev
else:
    print('The data file is missing!')
        

Validate if the file exists (if/else)
Validate if the file exists (if/else)
