예제 #1
0
def _text(location, encoding, universal_new_lines=True):
    """
    Read file at `location` as a text file with the specified `encoding`. If
    `universal_new_lines` is True, update lines endings to be posix LF \n.
    Return a unicode string.
    Note:  Universal newlines in the codecs package was removed in
    Python2.6 see http://bugs.python.org/issue691291
    """
    with codecs.open(location, 'r', encoding) as f:
        text = f.read()
        if universal_new_lines:
            text = u'\n'.join(text.splitlines(False))
        return text
예제 #2
0
def _text(location, encoding, universal_new_lines=True):
    """
    Read file at `location` as a text file with the specified `encoding`. If
    `universal_new_lines` is True, update lines endings to be posix LF \n.
    Return a unicode string.
    Note:  Universal newlines in the codecs package was removed in
    Python2.6 see http://bugs.python.org/issue691291
    """
    with codecs.open(location, 'r', encoding) as f:
        text = f.read()
        if universal_new_lines:
            text = u'\n'.join(text.splitlines(False))
        return text