我有以下代码
#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\\fme\SU2745.asc', 'wb')
TypeError: 'unicode' object is not callable
如果我以相同的顺序单独运行sequence.py
中包含的脚本,它可以正常工作。当我通过另一个脚本触发脚本时,为什么会看到此错误?如何解决此问题?
TIA
答案 0 :(得分:3)
您可能已经为文件分配了一个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