Relative Python newbie, and I'm writing a script that takes as its input a csv file, splits it into its constituent fields line-by-line and spits it out in another format. What I have so far generally works very well.
Each incoming csv line has specific fields that are read into variables 'txnname' and 'txnmemo' respectively. Before I write out the line containing these, I need to test them for specific string sequences and modify them as necessary. At the moment I have these tests hard coded into the script as follows
if ('string1' in txnname) and ('string2' in txnmemo):
txnname = 'string3'
if 'string4' in txnname:
txnname = 'string5 ' + txnmemo
'stringx' is being used here replacing the actual text I'd like to use.
What I'd really like to do is to remove the search strings, variable names and modifier strings from the script altogether and place them in a config file that already exists alongside the script and contains various parameters read into the script via ConfigParser. That way I won't have to modify the code every time I want to test a new condition. The 'hacky' way of doing this would seem to be using eval/exec in some combination on the literal Python statements read in from the config file, however just about everybody says that there is nearly always a better alternative to eval/exec. However I can't come up with what this alternative would be despite much research. I've read mention of using dictionaries somehow, but can't get my head round how this would work, especially on an 'If' statement with more than one condition to be tested (as above)
Any advice gratefully received.