-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathessa_par.py
More file actions
71 lines (68 loc) · 2.22 KB
/
essa_par.py
File metadata and controls
71 lines (68 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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<len(attr_str)):
#print 'k in this function:%i'%k
ch = attr_str[k]
k += 1
if ch==',':
#print "Add param:",current_param
params.append(current_param)
current_param = ''
elif ch=='(':
nv = attr_str[k:]
#print "Up one level parenthesis:%s"%(nv)
current_param, progress = process_nested_parent_str2(nv)
#print "Adding the list returned from nested",current_param
params.append(current_param)
current_param = ''
k += progress+1
elif ch==')':
#print "Down one level parenthesis: %i characters parsed"%k
params.append(current_param)
#print "Current params:",params#k -= acc-2
return params,k
else:
current_param += ch
#print "Ch:",ch
#print "k:",k
#raw_input("")
#idx += 1
params.append(current_param)
return params,k
#print process_nested_parent_str2('1,2,3,4,5,6')
#idx=0
#print process_nested_parent_str2("'A','B','C'")
print(process_nested_parent_str2("'A'")[0])
print(process_nested_parent_str2("30.0,0.0,5.0")[0])
print(process_nested_parent_str2("(Thomas)")[0])
print(process_nested_parent_str2("Thomas, Paviot, ouais")[0])
print(process_nested_parent_str2("1,2,(3,4,5),6,7,8")[0])
print(process_nested_parent_str2("(#9149,#9166),#9142,.T.")[0])