I have a code section where I must select one of 4 pyparsing classes based on the settings of 2 arguments - whether to match a string with or without case sensitivity, and as or as not a keyword.
See examples below - I had hoped to make this a poll, but apparently my client will only permit images _or_ polling :( So respond in replies please. #python
@ptmcg I think 1 is more readable, but I like the declarative direction you're going with 2. I think 1 would be even more readable with ternary operators (aka conditional expressions), whereas 2 would be more readable if you could find a way to express those caseless/asKeyword notions more semantically in each line. You might also want to do some reading on the Factory pattern on Python if you're not familiar with it, since it was designed for this kind of situation.
@micahellison I could define some throwaway values of True that are semantically relevant (see below).
And thanks for the suggestion about the Factory pattern - I've used it before, but didn't really consider it here. Feel free to look into pyparsing and submit a PR.