Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 using a try/except in a conditional expression
#1
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.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)