Nov-15-2018, 01:46 PM
import glob def parse_line(line): for item in ['Emp No', 'Name', 'SAL']: 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: # No need to specify 'r': this is the default. line = f.readlines()[6] print(line) return parse_line(line) pattern = 'C:/Test/Python/Mag/*.txt' files = glob.glob(pattern) for file_name in files: # 'file' is a builtin type, 'name' is a less-ambiguous variable name. emp_no, emp_name, emp_sal = process_file(file_name) # here add code to write to DBadd a print as line 11 in process_file, this way you will see what the line 7 is. I guess you have other files that do not fit the format provided
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs