Skip to content

[Feature] Support context manager #213

@Vimos

Description

@Vimos

"Context managers allow you to allocate and release resources precisely when you want to. "

当前文档使用方法

from pyltp import Segmentor
segmentor = Segmentor()  # 初始化实例
segmentor.load(cws_model_path)  # 加载模型
words = segmentor.segment('元芳你怎么看')  # 分词
print '\t'.join(words)
segmentor.release()  # 释放模型

可否支持Context Manager,可以节省释放模型的过程

from pyltp import Segmentor
with Segmentor() as segmentor: # 初始化实例
    segmentor.load(cws_model_path)  # 加载模型
    words = segmentor.segment('元芳你怎么看')  # 分词
    print('\t'.join(words))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions