def splitByCommas(str):
 out = []
 if (not str):
  return out
 current = ''
 openQuotes = '"\'<({'
 closeQuotes = '"\'>)}'
 matchingQuote = ''
 insideQuotes = False
 nextIsLiteral = False
 for char in str:
  if nextIsLiteral:
   current += char
   nextIsLiteral = False
  elif insideQuotes:
   if (char == '\\'):
    nextIsLiteral = True
   else:
    current += char
    if (char == matchingQuote):
     insideQuotes = False
  elif (char == ','):
   out.append(current.strip())
   current = ''
  else:
   current += char
   quoteIndex = openQuotes.find(char)
   if (quoteIndex > (-1)):
    matchingQuote = closeQuotes[quoteIndex]
    insideQuotes = True
 out.append(current.strip())
 return out

def splitByCommas ( str ) : out = [ ] if ( not str ) : return out current = '' openQuotes = '"\'<({' closeQuotes = '"\'>)}' matchingQuote = '' insideQuotes = False nextIsLiteral = False for char in str : if nextIsLiteral : current += char nextIsLiteral = False elif insideQuotes : if ( char == '\\' ) : nextIsLiteral = True else : current += char if ( char == matchingQuote ) : insideQuotes = False elif ( char == ',' ) : out . append ( current . strip ( ) ) current = '' else : current += char quoteIndex = openQuotes . find ( char ) if ( quoteIndex > ( - 1 ) ) : matchingQuote = closeQuotes [ quoteIndex ] insideQuotes = True out . append ( current . strip ( ) ) return out
split a string by unenclosed commas: that is .