In this case, it would be painful to write all lambda expressions as a separate function.
What does this code briefly do? Converts a custom excel table into an insert statement for a custom database table. There is a mapping of excel field fields and database fields, as well as a mapping between excel fields and functions that must be applied to an excel table value before it is inserted into db. You really do not want to define a separate function for each field.
map_func = { 'ID' : lambda x : 'mig_farm_seq.nextval', 'ENTERPRISE_NAME' : wrap_str, 'TAX_NUMBER' : wrap_str, 'FAMILY_NAME' : lambda x : wrap_str(x.split()[0]), 'GIVEN_NAME' : lambda x : wrap_str(x.split()[1]), 'ENTERPRISE_REGISTRATION_NUMBER' : wrap_str, 'PREMISE_NAME' : wrap_str, 'HOUSE_ID' : wrap_str, 'POSTAL_CODE' : wrap_str, 'PHONE_NUMBER_1' : lambda x : wrap_str(get_phone_number(x, True)), 'PHONE_NUMBER_2' : lambda x : wrap_str(get_phone_number(x, False)), 'FAX_NUMBER' : lambda x : wrap_str(x.replace(' ', '')), 'BANK_IDENTIFIER' : lambda x : wrap_str(x.replace(' ', '').replace('-', '')[:3]), 'BANK_ACCOUNT_NUMBER' : lambda x : wrap_str(x.replace(' ', '').replace('-', '')), 'NUMBER_OF_EMPLOYEES' : wrap_null, 'SETTLEMENT_NUMBER' : wrap_null, 'REGISTRATION_NUMBER' : lambda x : insert_reg_number % x, 'GENDER' : wrap_str, 'ACTIVITY' : lambda x : '0', 'REG_HOLDER_ACTIVITY' : lambda x : '0', 'PROCESSED_BY_JOB' : lambda x : '0' }
source: http://pastebin.com/MxEPBMaZ
source share