Note that maximum recursion depth is quite small by default (1k on python 2.17 on my box). This can be checked by running:
import sys
print(sys.getrecursionlimit())
In most cases (to avoid hitting recursion limit) you can make your code iterative, here is good article about recursion-to-iteration.
Anyway, if your snippet is indeed an instance method, as 'self' could suggest, you can simply add an instance property, that would contain current value. Example:
class UselessObject(object):
def __init__(self, start_value=0):
self.value = start_value
@staticmethod
def is_numeric(s):
try:
float(s)
return True
except (ValueError, TypeError):
return False
def addDigit(self, number):
assert self.is_numeric(number), "non-numeric value provided"
if str(number).__len__() == 1:
self.value += number
else:
self.value += (number - number%10)/10 + number%10