我使用urllib3从https://www.clres.com/db/parses/oec/abaft.parse获得了一个文件。它有制表符,然后是\r\n。在Python2.7中,我使用的是StringIO,但在Python3.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
StringIO
在python3.7中可用memory_file
是一个字符串,因此要获得每一行,您需要split
:在
memory_file
中,已经从服务器加载了数据。要拆分数据,请使用splitlines()
和split()
:印刷品:
相关问题 更多 >
编程相关推荐