def trickySplit(line, delim):
  """trickySplit(line, delim) - split line by delimiter delim, but ignoring delimiters found inside (), [], {}, ''' and "".
    
    eg: trickySplit("email(root,'hi there'),system('echo hi, mum')", ',')
    would return: ["email(root,'hi there'", "system('echo hi, mum')"]
  """
  parenCnt = 0   # ()
  curlyCnt = 0   # {}
  squareCnt = 0  # []
  doubleqCnt = 0 # ""
  quoteCnt = 0   # ''
  
  splitList = [] # split strings
  current = ''   # current split string'
  
  for c in line:
    if c == '(':
      parenCnt += 1
    elif c == ')':
      parenCnt -= 1
    elif c == '{':
      curlyCnt += 1
    elif c == '}':
      curlyCnt -= 1
    elif c == '[':
      squareCnt += 1
    elif c == ']':
      squareCnt -= 1
    elif c == '"':
      doubleqCnt = 1 - doubleqCnt
    elif c == '\'':
      quoteCnt = 1 - quoteCnt
    elif c == delim:
      if parenCnt == 0 and curlyCnt == 0 and squareCnt == 0 and doubleqCnt == 0 and quoteCnt == 0:
        splitList.append(current)
        current = ''
        continue
    
    current += c
  if len(current) > 0:
    splitList.append(current)
  
  return splitList