社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

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

Haz • 4 年前 • 273 次点击  

我想用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
 
273 次点击  
文章 [ 2 ]  |  最新文章 4 年前
Urvi Soni
Reply   •   1 楼
Urvi Soni    4 年前

你可以试试这个。。。

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    4 年前

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