Python Forum
using a try/except in a conditional expression
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
using a try/except in a conditional expression - by Skaperen - Aug-13-2019, 02:46 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020