while True: print(li) list_ex = re.split(‘\(([^()]*)\)‘,li,1) print(list_ex) if len(list_ex) == 3: before = list_ex[0] content = list_ex[1] after = list_ex[2] s1 = eval(content) new_ex = before + str(s1) +after li = new_ex elif len(list_ex) == 1: s2 = eval(content) print(s2) break
原文:http://www.cnblogs.com/zhangyanhui/p/7979125.html