my String looks like:
"('f', ('d', ('a', 'b')), 'g')"
I want to convert that to tuple.
How can do that… I will use that in drawing a dendogram
Edit:
additional explanation:
my code and output’s (print’s):
print type(myString) # <type 'str'>
print myString #('f',('d',('a','b')),'g')
myString = ast.literal_eval(myString)
print type(myString) #<type 'tuple'>
print myString #('f', ('d', ('a', 'b')), 'g')
for tuple in myString: #f
print tuple #('d', ('a', 'b'))
#g
Use
ast.literal_eval.This will not let some malicious scripts run from the string provided as with
eval.