我在一臺機器上獲得「在分配」之前引用了「UnboundLocalError:本地變量」的python腳本,但在腳本運行正常的另一臺機器上沒有。這兩臺機器都在Windows 7上並使用Python 2.7.3。任何建議可能是這種行爲的原因?謝謝。 下面是導致該錯誤代碼:Python在一臺機器上未綁定本地錯誤,但不在另一臺機器上
with open(self.temp_dir + test + ".log",'r') as log:
for line in log:
if "INPUT_SENTENCE" in line:
match = patternInput.match(line)
inputSentence = match.group(1).lower()
if inputSentence in self.testToDiagDict[test]:
continue
self.testToDiagDict[test][inputSentence] = []
if "STATS" in line:
if "Input Sentences" in line:
inputSentences = patternValue.findall(line)
self.testToDiagDict[test][inputSentence].append(inputSentences[0])
和Trace:
File "C:\X\Y\X\script.py", line 90, in extract_data
if "Input Sentences" in line:
UnboundLocalError: local variable 'inputSentence' referenced before assignment
'UnboundLocalError' is一個*運行時*異常,而不是語法錯誤。我們需要查看您的代碼才能提供幫助。 –
請提供更多的細節 - 一些代碼會很好,並追溯。 – matino
檢查它在工作的機器上是指什麼。除了錯誤以外,劇本會做什麼? – Joop