Python社区  »  Python

使用python识别段落中的第一个句子

Haz • 2 周前 • 22 次点击  

我想用python从一个段落中得到第一句话。 以下段落

ECONOMYNEXT-市场人士表示,斯里兰卡卢比兑美元周五收报176.40/50卢比,金边收益率小幅走高,因二级市场获利回吐,尽管央行下调政策利率以恢复信贷需求,但股市收跌0.26%。

周四,在现货市场上,卢比兑美元收于176.40/50卢比。

我是从下面的代码中提取这个句子的 小数点。谢谢你的帮助。

import requests
#from pprint import pprint
from IPython.display import HTML
import json


txt = ''' ECONOMYNEXT -Sri Lanka rupee closed steady at 176.40/50 rupees to the US dollar on Friday and gilt yields edged higher on profit taking in the secondary market even as the Central Bank cut policy rates to revive credit demand, while stocks ended 0.26 percent lower, market participants said.

The rupee ended at 176.40/50 rupees against the greenback in the spot market on Thursday. '''

if len(txt) > 100:
    txt = txt.partition('.')[0] + '.'
print(txt)
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/49237
 
22 次点击  
分享到微博
文章 [ 2 ]  |  最新文章 2 周前
Urvi Soni
Reply   •   1 楼
Urvi Soni    5 月前

你可以试试这个。。。

txt = " ECONOMYNEXT -Sri Lanka rupee closed steady at 176.40/50 rupees to the US 
        dollar on Friday and gilt yields edged higher on profit taking in the 
        secondary market even as the Central Bank cut policy rates to revive credit 
        demand, while stocks ended 0.26 percent lower, market participants said. The 
        rupee ended at 176.40/50 rupees against the greenback in the spot market on 
        Thursday. "

sentence_index = txt.find('. ')

print(txt[0: sentence_index])

你将得到如下输出

ECONOMYNEXT-市场人士表示,斯里兰卡卢比兑美元周五收稳在176.40/50卢比,金边收益率小幅上升,因二级市场获利回吐,尽管央行下调政策利率以恢复信贷需求,但股市收跌0.26%

DijkWxyZ
Reply   •   2 楼
DijkWxyZ    5 月前

试图与 '. ' (有空格)和 '.\n'