def smart_open(file_path_name,
        mode='r',
        encoding='utf-8'):
    """
    Open an encoded file using the given mode and return a wrapped version
    providing transparent encoding/decoding.  The default file mode is 'r'
    meaning to open the file in read mode.


    @param file_path_name: the absolute path and name of the file to
        open.

    @param mode: indicate how the file is to be opened.  The most
        commonly-used values of mode are 'r' for reading, 'w' for
        writing (truncating the file if it already exists), and 'a'
        for appending (which on some Unix systems means that all writes
        append to the end of the file regardless of the current seek
        position). If mode is omitted, it defaults to 'r'.

    @param encoding: specify the encoding which is to be used for the
        file.


    @return: an object of the file type.
    """
    if file_path_name and file_path_name != '-':
        file_handle = codecs.open(file_path_name, mode=mode, encoding='utf-8')
    else:
        file_handle = sys.stdout

    try:
        yield file_handle
    finally:
        if file_handle is not sys.stdout:
            file_handle.close()
def smart_open ( file_path_name , mode = 'r' , encoding = 'utf-8' ) : if file_path_name and file_path_name != '-' : file_handle = codecs . open ( file_path_name , mode = mode , encoding = 'utf-8' ) else : file_handle = sys . stdout try : yield file_handle finally : if file_handle is not sys . stdout : file_handle . close ( )
Open an encoded file using the given mode and return a wrapped version
    providing transparent encoding/decoding.  The default file mode is 'r'
    meaning to open the file in read mode.


    @param file_path_name: the absolute path and name of the file to
        open.

    @param mode: indicate how the file is to be opened.  The most
        commonly-used values of mode are 'r' for reading, 'w' for
        writing (truncating the file if it already exists), and 'a'
        for appending (which on some Unix systems means that all writes
        append to the end of the file regardless of the current seek
        position). If mode is omitted, it defaults to 'r'.

    @param encoding: specify the encoding which is to be used for the
        file.


    @return: an object of the file type.