How to protect against such a situation? if x=1 its OK, but when x=0:
def test():
x=0
if (x == 0): return 0
else:
return 'abc', 100, 200
a, b, c = test()
print(b)
TypeError: cannot unpack non-iterable int object.
Maybe such a solution would be better ?
class ReturnValue:
def __init__(self):
self.a = "a"
self.b = 100
self.c = 200
def test():
return ReturnValue()
t = test()
if (t):
print("%s, %s, %s" % (t.a,t.b,t.c))
else:
print("error")