def process_nested_parent_str(attr_str): ''' The first letter should be a parenthesis input string: "(1,4,(5,6),7)" output: tuple (1,4,(4,6),7) ''' params = [] agg_scope_level = 0 current_param = '' for i,ch in enumerate(attr_str): if ch==',': params.append(current_param) current_param = '' elif ch=='(': agg_scope_level +=1 elif ch==')': agg_scope_level = 0 elif agg_scope_level == 0: current_param += ch return params def process_nested_parent_str2(attr_str,idx=0): ''' The first letter should be a parenthesis input string: "(1,4,(5,6),7)" output: ['1','4',['5','6'],'7'] ''' #print 'Entering function with string %s'%(attr_str) params = [] current_param = '' k = 0 while (k