首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >python删除文本文件中具有特定结束行的特定起始行

python删除文本文件中具有特定结束行的特定起始行
EN

Stack Overflow用户
提问于 2017-02-10 14:31:16
回答 1查看 34关注 0票数 1

我有如下数据:

代码语言:javascript
复制
test="1. My Contact Number (Nortel/Mobile): 7774096182 2. My Preferred Time (in IST) to be contacted: 11am to 8pm Please book a daily bridge line, below are the details: Start Date: 06-July-2016 End Date: 05-Aug-2016 Time: 3 pm to 6 pm ( 3-hr duration) Number of participants: 25 on every friday We require the bridge line daily during this slot. Regards, Smriti Varma."

test1="Hi Team, Please arrange Audio Bridge call thru Nortel & Landline only for tomorrow Dated 16-Jun-2016 between 12.30 PM to 1.30 PM (IST), Number of Paticipants: 06 1. My Contact Number (Nortel/Mobile): 2. My Preferred Time (in IST) to be contacted:"

我不想同时使用这两行:

代码语言:javascript
复制
text="1. My Contact Number (Nortel/Mobile): 2. My Preferred Time (in IST) to be contacted:","1. My Contact Number (Nortel/Mobile): 7774096182 2. My Preferred Time (in IST) to be contacted: 11am to 8pm"
EN

回答 1

Stack Overflow用户

发布于 2017-02-10 19:25:52

我不知道您想要的最终结果是什么,但您可以使用str.replace()

所以就像这样:

代码语言:javascript
复制
test = "1. My Contact Number (Nortel/Mobile): 7774096182 2. My Preferred Time (in IST) to be contacted: 11am to 8pm Please book a daily bridge line, below are the details: Start Date: 06-July-2016 End Date: 05-Aug-2016 Time: 3 pm to 6 pm ( 3-hr duration) Number of participants: 25 on every friday We require the bridge line daily during this slot. Regards, Smriti Varma."

test1 = "Hi Team, Please arrange Audio Bridge call thru Nortel & Landline only for tomorrow Dated 16-Jun-2016 between 12.30 PM to 1.30 PM (IST), Number of Paticipants: 06 1. My Contact Number (Nortel/Mobile): 2. My Preferred Time (in IST) to be contacted:"

text = ["1. My Contact Number (Nortel/Mobile): 2. My Preferred Time (in IST) to be contacted:","1. My Contact Number (Nortel/Mobile): 7774096182 2. My Preferred Time (in IST) to be contacted: 11am to 8pm"]

test_modified = test.replace(text[0], "")
test1_modified = test1.replace(text[1], "")

How to use string.replace() in python 3.x

但这取决于你的"test“字符串的复杂程度,如果你想一般地查找它们的话。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42152883

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档