def convert_to_lines(tokens):
"""
Given a stream of tokens, yield lines as strings.
Each output string is guaranteed to end with a newline.
"""
line = []
for token in tokens:
text = get_token_text(token)
line.append(text)
if text == '\n':
yield ''.join(line)
line = []
if line:
line.append('\n')
yield ''.join(line)
working_with_tokens.py 文件源码
python
阅读 18
收藏 0
点赞 0
评论 0
评论列表
文章目录