Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python中的格式错误_Python - Fatal编程技术网

Python中的格式错误

Python中的格式错误,python,Python,我从来没有使用过Python,并且从网上的某个人那里复制了一些脚本(在获得许可的情况下),所以我不知道为什么代码会被删除。我希望有人能理解它,帮我纠正错误 from os import walk from os.path import join #First some options here. !RootDir = "C:\\Users\\***\\Documents\\GoGames" !OutputFile = "C:\\Users\\***\\Docum

我从来没有使用过Python,并且从网上的某个人那里复制了一些脚本(在获得许可的情况下),所以我不知道为什么代码会被删除。我希望有人能理解它,帮我纠正错误

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."
使用Netbeans IDE时,我遇到以下错误:

  !RootDir     = "C:\\Users\\***\\Documents\\GoGames"
  ^
SyntaxError: mismatched input '' expecting EOF
我以前能够单步执行代码,直到file.close(),其中出现错误“与外部缩进级别不匹配”


有人能帮我把这段代码的语法写对吗?

删除变量名、列表声明(
!![]
)前面的感叹号,以及
子句(
除!ValueError
)之外的
中的感叹号,这是无效的Python语法。

代码还需要按缩进和间距进行清理。。。以及糟糕的命名(OP应该遵循PEP8并修复该脚本)。