Define function to Open a file : IO Error : File PYTHON examples


PYTHON examples » File » IO Error »

 

Define function to Open a file


Define function to Open a file

import sys

def open_file(file_name, mode):
    """Open a file."""
    try:
        the_file = open(file_name, mode)
    except(IOError), e:
        print "Unable to open the file", file_name, "Ending program.n", e
        raw_input("nnPress the enter key to exit.")
        sys.exit()
    else:
        return the_file

trivia_file = open_file("trivia.txt""r")


           
       



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON examples

 Navioo File
» IO Error


Warning: Unknown: write failed: No space left on device (28) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0