Python 3.x python删除文本文件中带有特定结束行的特定起始行
我有如下数据:Python 3.x python删除文本文件中带有特定结束行的特定起始行,python-3.x,anaconda,Python 3.x,Anaconda,我有如下数据: 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
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 = "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], "")
但是,如果您想查找“测试”字符串,这取决于其复杂性 我不知道您想要的最终结果是什么,但您可以使用。
比如:
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], "")
但是,如果您想查找“测试”字符串,这取决于其复杂性