Skip to content

Instantly share code, notes, and snippets.

@rambo
Created January 18, 2019 19:12
Show Gist options
  • Save rambo/7bf3cb441bc2d625854901a11df2e701 to your computer and use it in GitHub Desktop.
Save rambo/7bf3cb441bc2d625854901a11df2e701 to your computer and use it in GitHub Desktop.
Python class method recursion test
rambombp2015-674:Downloads rambo$ python2.7 rec_test.py
level is 0
level is 1
level is 2
level is 3
level is 4
level is 5
level is 6
level is 7
level is 8
level is 9
level is 10
level is 11
level is 12
level is 13
level is 14
level is 15
level is 16
level is 17
level is 18
level is 19
level is 20
level is 21
level is 22
level is 23
level is 24
level is 25
level is 26
level is 27
level is 28
level is 29
level is 30
level is 31
level is 32
level is 33
level is 34
level is 35
level is 36
level is 37
level is 38
level is 39
level is 40
level is 41
level is 42
level is 43
level is 44
level is 45
level is 46
level is 47
level is 48
level is 49
level is 50
rambombp2015-674:Downloads rambo$ python3.7 rec_test.py
level is 0
level is 1
level is 2
level is 3
level is 4
level is 5
level is 6
level is 7
level is 8
level is 9
level is 10
level is 11
level is 12
level is 13
level is 14
level is 15
level is 16
level is 17
level is 18
level is 19
level is 20
level is 21
level is 22
level is 23
level is 24
level is 25
level is 26
level is 27
level is 28
level is 29
level is 30
level is 31
level is 32
level is 33
level is 34
level is 35
level is 36
level is 37
level is 38
level is 39
level is 40
level is 41
level is 42
level is 43
level is 44
level is 45
level is 46
level is 47
level is 48
level is 49
level is 50
from __future__ import (absolute_import, division, # Python3 compatibility
print_function)
class RecursionTest(object):
limit = 50
def recurser(self, lvl=0):
if lvl > self.limit:
return
print("level is {}".format(lvl))
self.recurser(lvl+1)
if __name__ == '__main__':
i = RecursionTest()
i.recurser()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment