title: Count Parenthesis in a file with a Python program?
body: <p>I Wanna fix a function through it i can count how many times are used the:(,),[,]
  if the counts of ( are equal to those of )
  and if the counts of [ are equal to those of ]
  then i have valid syntax!</p>
  
  <p>my first -dissapointed- try:</p>
  
  <pre><code>filename=input("Give a file name:")
  
  def  parenthesis(filename):
      try:
          f=open(filename,'r')
      except (IOError):
          print("The file",filename,"does not exist!False! Try again!")
      else:
           while True:
              for line in filename:
                  line=f.readline()
                  if line=='(':
                       c1=line.count('(')
                  elif line==')':
                       c2=line.count(')')
                  elif line=='[':
                       c3=line.count('[')
                  elif line==']':
                       c4=line.count(']')
                  elif line=='':
                      break
  
                  if c1==c2:
                       print("Line: Valid Syntax")
                  elif c1!=c2:
                       print("Line: InValid Syntax")
                  elif c3==c4:
                       print("Line: Valid Syntax")
                  elif c3!=c4:
                       print("Line: InValid Syntax")
      finally:
          f.close()
  
  parenthesis(filename)
  </code></pre>