Aug-13-2019, 02:46 AM
i needed to make a conditional expression that included testing if a file exists. so i wrote a small function to call os.lstat() in a try/except returning True or False. then i call that function in the expression.
i want to generalize this so what is to be done is passed to a generalized function in the call arguments so i don't need to create a function for each different one of these i might need to include in a boolean expression. does anything like this already exist?
i'm thinking of passing lists of strings with code to exec(), the 1st for lines under try: and the others for the exceptions to handle and their code lines. this would be put together somehow. since i can't do returns in exec() i will need to think up a good design for having the caller specify what and where to return.
i want to generalize this so what is to be done is passed to a generalized function in the call arguments so i don't need to create a function for each different one of these i might need to include in a boolean expression. does anything like this already exist?
i'm thinking of passing lists of strings with code to exec(), the 1st for lines under try: and the others for the exceptions to handle and their code lines. this would be put together somehow. since i can't do returns in exec() i will need to think up a good design for having the caller specify what and where to return.