x=something, y=somethinelse and z=crud all likely to fail - how do i wrap them up

Veek. M vek.m1234 at gmail.com
Sat Jan 30 23:58:25 EST 2016


I'm parsing html and i'm doing:

x = root.find_class(...
y = root.find_class(..
z = root.find_class(..

all 3 are likely to fail so typically i'd have to stick it in a try. This is 
a huge pain for obvious reasons.

try:
 ....
except something:
 x = 'default_1'
(repeat 3 times)

Is there some other nice way to wrap this stuff up?
I can't do:
try:
 x=
 y=
 z=
except:

because here if x fails, y and z might have succeeded.

Pass the statement as a string to a try function? Any other way?



More information about the Python-list mailing list