类型错误:'unicode'对象不可调用 - 仅当通过另一个调用脚本时才会发生错误



>我有以下代码

#unzip
inF = gzip.GzipFile(os.path.join(homePath), 'rb')
s = inF.read()
inF.close()
outfile = homeDir[0:14]+'\fme\'+gridRef+".asc"
outfile = outfile.encode('ascii', 'ignore')
print 'outfile is', outfile
outF = file(outfile, 'wb')
outF.write(s)
outF.close()

从另一个脚本sequence.py调用并引发以下错误

  File "gridFunction.py", line 164, in <module>
    outF = file('C:LiDAR_Temp\fmeSU2745.asc', 'wb')
TypeError: 'unicode' object is not callable

如果我以相同的顺序单独运行sequence.py中包含的脚本,它可以正常工作。为什么当我通过另一个脚本触发脚本时会看到此错误,我该如何解决问题?

蒂亚

您可能已经为文件分配了一个 Unicode 字符串,覆盖了内置的文件对象,因此它不再可调用。 例:

Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> file = u'abc'
>>> file('out.txt','wb')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'unicode' object is not callable

最新更新