def str_base(number, base):
    if number < 0:
        return '-' + str_base(-number, base)
d, m = divmod(number, base)
if d > 0:
    return str_base(d, base) + digit_to_char(m)
return digit_to_char(m)
Python elegant inverse function of int(string,base)