No revelation here for the guys who are not beginners in Python . And maybe there is a better way to do it.
But when you pass tuples as params to your own methods/func, it's all ok as long as you pass more than one value in your tuple. If you pass like (10,1) it will be ok. But if you pass one value like (10) it will not be ok. Is not a tuple. It has to be (10,)
I do know this, but it's frustrating as I forget sometimes. I was doing something today exactly like this.
Anyway, I did the below. I hope it helps, or maybe better ideas emerge
def accept_a_tuple(tp):
try:
for v in tp:
print(v)
except:
print('this fails')
def accept_a_tuple_better(tp):
# headache saver when passing a single value tuple without a comma
if not isinstance(tp, tuple):
tp = (tp,)
for v in tp:
print(v)
accept_a_tuple((20,)) # is ok, we remember the comma
accept_a_tuple((10)) # this fails, is not a tuple
accept_a_tuple_better((10)) # i think this is a better way