Nov-16-2018, 12:43 PM
(This post was last modified: Nov-16-2018, 12:43 PM by ganeshsai2912.)
I writing python program which read specific text from text file.
The program is working fine if it is static line index.
if it is dynamic search in the whole document, i am unable to read..
particularly, i want to get "Join Date","Relieve Date",etc. along with 3 main parameter(EmpNo,Name,Salary).
How to change the below code..?
final out put would be
EmpNo: 101 Name: RASUL L SAL: 30000 JoinDate :XXXXX
Sample file attached.
Sample file attached
The program is working fine if it is static line index.
if it is dynamic search in the whole document, i am unable to read..
particularly, i want to get "Join Date","Relieve Date",etc. along with 3 main parameter(EmpNo,Name,Salary).
How to change the below code..?
import glob def parse_line(line): for item in ['Emp No', 'Name', 'SAL', 'Join Date']: line = line.replace(item, '') return [item.strip() for item in line.split(':') if item.strip()] def process_file(file_name): with open(file_name) as f: line = f.readlines()[6] print(line) return parse_line(line) pattern = 'C:/Test/Python/Project/*.txt' files = glob.glob(pattern) all_data = [process_file(file_name) for file_name in files]sample text file attached in the below link.
final out put would be
EmpNo: 101 Name: RASUL L SAL: 30000 JoinDate :XXXXX
Sample file attached.
Sample file attached