import codecs


def text2lines(textpath, lines_content=None):
    """
    read lines from text or write lines to txt
    :param textpath: filepath of text
    :param lines_content: list of lines or None, None means read
    :return: processed lines content for read while None for write
    """
    if lines_content is None:
        with codecs.open(textpath, 'r') as handle:
            lines_content = handle.readlines()
        processed_lines = list(map(lambda x: x[:-1] if x[-1] in ['\n'] else x, lines_content))
        return processed_lines
    else:
        processed_lines = list(map(lambda x: x if x[-1] in ['\n'] else '{}\n'.format(x), lines_content))
        with codecs.open(textpath, 'w') as handle:
            handle.write(''.join(processed_lines))
        return None