gpt4 book ai didi

python - 根据分隔符的多次出现分割文件

转载 作者:行者123 更新时间:2023-12-01 04:13:32 26 4
gpt4 key购买 nike

我遇到了以下任务,根据分隔符的多次出现来拆分文件。
我有一个包含以下数据的文件:

Number of Employees       - 95

==============================================================================
Telephone Number - 972123111111
Empl Name - David
Designation - Software Engineer
Address: **********
Doamin: Python
==============================================================================
Telephone Number - 972123111112
Empl Name - Glen
Designation - Software Engineer
Doamin: Python
==============================================================================
Telephone Number - 972123111111
Empl Name - Jhon
Designation - Software Engineer
Address: **********
Doamin: Python
==============================================================================

在此文件中,我想将每个员工信息拆分在“=”之间,然后打印所有员工的内容,如下所示:

Details of Employee: (Employee Name)
Telephone Number: (employee telephone number)
Designation : (employee desgination)

我已经编写了从文件中将数据提取到变量中的代码,并使用下面的正则表达式来 grep 数据,但没有效果:

re.findall('[^=]=*.*?[=*$]', a)

最佳答案

使用re.split()而不是像这样的 re.findall() :

re.findall(r'^=+$', a)

关于python - 根据分隔符的多次出现分割文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34586851/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com