Usage

Installation

To use nlpertools, first install it using pip:

(.venv) $ pip install nlpertools

Writing a file

To write a txt file, you can use the nlpertools.readtxt_list_all_strip() function:

Source code in src/nlpertools/io/file.py
55
56
57
58
59
60
61
62
63
64
65
66
def readtxt_list_all_strip(path, encoding='utf-8'):
    file_line_num = iter_count(path)
    lines = []
    with codecs.open(path, 'r', encoding) as r:
        if file_line_num > LARGE_FILE_THRESHOLD:
            iter_obj = tqdm(enumerate(r.readlines()), total=file_line_num)
        else:
            iter_obj = enumerate(r.readlines())

        for ldx, line in iter_obj:
            lines.append(line.strip('\n').strip("\r"))
        return lines


For example:

>>> import nlpertools
# >>> nlpertools.readtxt_list_all_strip("res", "res.txt")