def strtotuple(s):
 if (not match('^[,.0-9 ()\\[\\]]*$', s)):
  raise Exception('Invalid characters in string for tuple conversion')
 if (s.count('(') != s.count(')')):
  raise Exception('Invalid count of ( and )')
 if (s.count('[') != s.count(']')):
  raise Exception('Invalid count of [ and ]')
 r = eval(s)
 if (type(r) not in (list, tuple)):
  raise Exception('Conversion failed')
 return r

def strtotuple ( s ) : if ( not match ( '^[,.0-9 ()\\[\\]]*$' , s ) ) : raise Exception ( 'Invalid characters in string for tuple conversion' ) if ( s . count ( '(' ) != s . count ( ')' ) ) : raise Exception ( 'Invalid count of ( and )' ) if ( s . count ( '[' ) != s . count ( ']' ) ) : raise Exception ( 'Invalid count of [ and ]' ) r = eval ( s ) if ( type ( r ) not in ( list , tuple ) ) : raise Exception ( 'Conversion failed' ) return r
convert a tuple string into a tuple with some security checks .