0

我参加的大学早期课程之一是 3 年前的 Python 基础培训。现在我正在寻找一个可以帮助我调整一些 Grid 东西大小的程序,我发现了一些可以在 Python 中帮助我的东西。我将 Python 重新安装到我的 PC 并找到了我的旧编辑器。但是,当我运行代码时,我得到一个我无法理解的无效语法错误。这是出现错误的代码部分:

def downsize(mode, cell_size, inpath, outpath):

  from VolumeData import fileformats
  try:
    grid_data = fileformats.open_file(inpath)
  except fileformats.Uknown_File_Type, e:
    sys.stderr.write(str(e))
    sys.exit(1)

  reduced = Reduced_Grid(grid_data, mode, cell_size)

  from VolumeData.netcdf.netcdf_grid import write_grid_as_netcdf
  write_grid_as_netcdf(reduced, outpath)

确切的无效语法错误在“除了 fileformats.Uknown_File_Type, e:”行中。你能帮助我吗 ?

4

2 回答 2

2

如果您使用的是 Python 3.x,则不能使用except fileformats.Uknown_File_Type, e. 逗号用作as语句(在try/except块中),因此您应该将其替换为:except fileformats.Uknown_File_Type as e

逗号适用于 Python 2.7,但不适用于 3.x。但是,as应该适用于两者。

参考:在 Python 3.3 中处理错误

于 2013-03-02T17:06:37.103 回答
0

也许你拼错了“未知”?

于 2013-03-02T17:01:22.127 回答