在Python中将Stanza转换为Paragraph

问题描述 投票:0回答:1

我正在尝试创建一个将节转换为段的python脚本。这种东西:

My mother’s maids, when they did sew and spin,
They sang sometimes a song of the field mouse,
That for because their livelihood was but so thin.

Would needs go seek her townish sister’s house.
Would needs She thought herself endured to much pain:
The stormy blasts her cave so sore did souse…

成为这样一个段落:

我母亲的女仆,当他们缝制和旋转时,他们有时会唱一首田鼠的歌,因为他们的生计只是如此之薄。需要去寻找她的乡镇妹妹的房子。需要她认为自己忍受了很大的痛苦:风雨如磐的爆炸她的洞穴疼痛咳嗽......

python-3.x
1个回答
0
投票

这是正则表达式的工作,而不是python。用\n+(单个空格)替换

Here’s a link to Regexr

© www.soinside.com 2019 - 2024. All rights reserved.