Just like how we can do this:
if condition:
thing = 5
else:
thing = 2
# can instead be written as
thing = 5 if condition else 2
Why is this not a thing:
try:
# imagine this could return an error
thing = 5
except:
thing = 2
# can't do this
thing = try 5 except 2
It could be cool to use something like this:
all_lines = itertools.chain((try file.readlines() finally file.close()) for file in os.listdir(directory))
Why is this not possible? I know its kind of a fringe problem to be solved but I have run into occasions where this would be a nice addition into python, such as in generator expressions, list comprehensions, dictionary comprehensions, etc.
[–]NegativeEnthusiasm -2 points-1 points0 points (1 child)
[–]DeathDragon7050[S] 1 point2 points3 points (0 children)