Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Support context manager #213

Closed
Vimos opened this issue Dec 11, 2019 · 0 comments
Closed

[Feature] Support context manager #213

Vimos opened this issue Dec 11, 2019 · 0 comments

Comments

@Vimos
Copy link

Vimos commented Dec 11, 2019

"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))
AlongWY added a commit that referenced this issue Aug 30, 2020
@AlongWY AlongWY closed this as completed Aug 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants