Formatting Errors in Python
Question: I've never used Python and have copied some script (with permission) from
someone online, so I'm not sure why the code is dropping. I'm hoping someone
can understand it and put it right for me!

    
    
    from os import walk
    from os.path import join
    
      #First some options here.
    
        !RootDir     = "C:\\Users\\***\\Documents\\GoGames"
        !OutputFile  = "C:\\Users\\***\\Documents\\GoGames\\protable.csv"
        Properties  = !!['pb', 'pw', 'br', 'wr', 'dt', 'ev', 're']
    
        print """
          SGF Database Maker
          ==================
    
          Use this program to create a CSV file with sgf info.
          """
    
        def getInfo(filename):
          """Read out file info here and return a dictionary with all the
          properties needed."""
          result = !![]
    
          file = open(filename, 'r')
          data = file.read(1024)  read at most 1kb since we assume all relevant info is in the beginning
          file.close()
    
          for prop in Properties:
              try:
                  i = data.lower().index(prop)
              except !ValueError:
                  result.append((prop, ''))
                  continue
              try:
                  value = data![data.index('![', i)+1 : data.index(']', i)]
              except !ValueError:
                  value = ''
    
              result.append((prop, value))
    
          return dict(result)
    
    
        !ProgressCounter = 0
    
        file = open(!OutputFile, "w")
        file.write('^Filename^;^PB^;^BR^;^PW^;^WR^;^RE^;^EV^;^DT^\n')
    
        for root, dirs, files in walk(!RootDir):
          for name in files:
              if name![-3:].lower() != "sgf":
                  continue
    
              info = getInfo(join(root, name))
    
              file.write('^'+join(root, name)+'^;^'+info!['pb']+'^;^'+info!['br']+'^;^'+info!['pw']+'^;^'+info!['wr']+'^;^'+info!['re']+'^;^'+info!['ev']+'^;^'+info!['dt']+'^\n')
              !ProgressCounter += 1
              if (!ProgressCounter) % 100 == 0:
                  print str(!ProgressCounter) + " games processed."
    
    
        file.close()
    
        print "A total of " + str(!ProgressCounter) + " have been processed."
    

Using Netbeans IDE I get the following error:

    
    
      !RootDir     = "C:\\Users\\***\\Documents\\GoGames"
      ^
    SyntaxError: mismatched input '' expecting EOF
    

I have previously been able to step through the code as far as file.close(),
where I go an error "does not match outer indentation level".

Anyone able to put the syntax of this code right for me?


Answer: Remove the exclamation marks in front of variable names, list declarations
(`!![]`) and in `except` clauses (`except !ValueError`), this is not valid
Python syntax.

