I am working on a class that has attributes depending from one another. When instantiated, the class should try to initiate all the attributes it can but is should skip the ones raising an exception.
Something like this:
def foo:
def __init__(self, a, b, c):
try: self.x = len(a)
except: pass
try: self.y = sum(b)
except: pass
try: self.z = c
except: pass
try: self.v = self.x + self.z
except: pass
try: self.w = self.x + self.y
except: pass
This works but it looks horrible. Is there a way to simplify this process?
Is there a way to achieve the same result with a cleaner code like the following?
def foo:
def __init__(self, a, b, c):
try:
self.x = len(a)
self.y = sum(b)
self.z = c
self.v = self.x + self.z
self.w = self.x + self.y
except:
continue_to_the_next_line()