Dec-18-2019, 01:52 PM
Hi
I am using the following code. Forgive the mess, and the murder of python conventions,
its my first project. I am trying to format a bank statement.
Why is it skipping the letter 'e' in Cheque?
If I substitute some other letter for 'e' in the raw_string, it gets printed.
And please also let me know how to shorten the full_transaction_type code that converts groups to a string.
Thanks
I am using the following code. Forgive the mess, and the murder of python conventions,

import re raw_string = " Inward Clg Cheque 25,319.00- 04NOV 13,164,022.62CR" # This is the first line of a record list_of_data = [] """A regular expression for starting line of record.""" record_start_identifier = re.compile(r''' (\s\w+)(\s\w+)?(\s\w+)?(\s\w+)?(\s\w+)?(\s\w+)?(\s\w+)?(\s\w+)?(\s\w+)?(\s\w+)? # Groups 1-10 of starting text with a leading space - upto max of 10 words \s+ # Spaces before start of transaction amount (\d+),?(\d*)?,?(\d*)?,?(\d*)?,?(\d*)?,?(\d*)?,?(\d*)?,?(\d*)?,?(\d*)?,?(\d*)? # Groups 11-20 of transaction amount \. # Decimal point dot (\d+) # Group 21 of numbers after decimal point (-?) # Group 22. If string is - it is a negetive number, else it is positive \s+ # Space after end of transation amount (\d{2}\w{3}) # Group 23 for date without year. \s+ # Space before start of cumulative balance (\d+),?(\d*)?,?(\d*)?,?(\d*)?,?(\d*)?,?(\d*)?,?(\d*)?,?(\d*)?,?(\d*)?,?(\d*)? # Groups 24-33 of balance amount \. # Decimal point dot (\d+) # Group 34 of numbers after decimal point ((CR)|(DR)) # Group 35 for debit or credit indicator ''', re.VERBOSE) def group_first_line(line): """Breaks record start line into groups.""" data_groups = record_start_identifier.search(line) return data_groups def convert_record_start_to_list(match_object, empty_list_to_update): """Convert the group created by group_first_line() into a list.""" first_word = match_object.group(1) first_word = first_word.lstrip() full_transaction_type = f"{first_word}{match_object.group(2)}{match_object.group(3)}{match_object.group(4)}{match_object.group(5)}{match_object.group(6)}{match_object.group(7)}{match_object.group(8)}{match_object.group(9)}{match_object.group(10)}" full_transaction_type = full_transaction_type.strip('None') empty_list_to_update.append(full_transaction_type) data_groups = group_first_line(raw_string) convert_record_start_to_list(data_groups, list_of_data) print(list_of_data)print result: ['Inward Clg Chequ']
Why is it skipping the letter 'e' in Cheque?

And please also let me know how to shorten the full_transaction_type code that converts groups to a string.
Thanks