Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make a parent function return - super return?

there is a check I need to perform after each subsequent step in a function, so I wanted to define that step as a function within a function.

>>> def gs(a,b):
...   def ry():
...     if a==b:
...       return a
...
...   ry()
...
...   a += 1
...   ry()
...
...   b*=2
...   ry()
... 
>>> gs(1,2) # should return 2
>>> gs(1,1) # should return 1
>>> gs(5,3) # should return 6
>>> gs(2,3) # should return 3

so how do I get gs to return 'a' from within ry? I thought of using super but think that's only for classes.

Thanks

There's been a little confusion... I only want to return a if a==b. if a!=b, then I don't want gs to return anything yet.

edit: I now think decorators might be the best solution.

like image 785
Jiaaro Avatar asked Nov 28 '22 21:11

Jiaaro


1 Answers

Do you mean?

def gs(a,b):
    def ry():
        if a==b:
            return a
    return ry()
like image 117
S.Lott Avatar answered Dec 09 '22 21:12

S.Lott