title: Python - reading lines from a file and ignoring lines between " "
body: <p>I wrote a code that reads a file and checks whether parentheses are balanced or not. I want to modify this code, where it reads a file and ignores parentheses in literal strings and literal characters, but I'm not too sure how to go upon doing this. Could anyone help me and give me an idea? Heres my code: </p>
  
  <pre><code>def isValidSource(fileName):    
      textFile = open(fileName)
      readFile = textFile.read()
      stack = []
      for line in readFile:
          for token in line:
              if token in "{[(":
                  stack.append( token )
              elif token in "}])":
                  if not len(stack):
                      return False, "Delimiters are not balanced"
                  else :
                      left = stack.pop()
                      print stack
                      if (token == "}" and left != "{") or \
                         (token == "]" and left != "[") or \
                         (token == ")" and left != "("):
                          return False, "Delimiters are not balanced"
      return not len(stack), "The stack is empty; all delimiters are paired and balanced"
  </code></pre>