【发布时间】:2019-11-19 09:29:47
【问题描述】:
我使用 urllib3 从 https://www.clres.com/db/parses/oec/abaft.parse 获得了一个文件。它有标签,然后是 \r\n。在 Python 2.7 中,我使用的是 StringIO,但这在 Python 3.7 中不可用。
由于StringIO已经被淘汰,我尝试使用IO。
http = urllib3.PoolManager(timeout=10.0)
r = http.urlopen('GET', url, preload_content=False)
remote_file = r.data
memory_file = remote_file.decode('utf-8')
prep_sents = get_sentences(memory_file)
def get_sentence(memory_file):
sentence = []
for line in memory_file:
if not re.match(r'\s*\r?\n', line):
我希望得到一行,但我只得到一行中的第一个标记。
1\tWith\twith\t_\tIN\t_\t0\tROOT\t_\t_\t_\t_\t_\t_\r\n
【问题讨论】:
标签: python io urllib3 stringio