私はPythonスクリプトから次のコード部分を持っています。Pythonスクリプトのexcept節にUnboundLocalErrorが表示されるのはなぜですか?
status = 'success'
try:
sqlContext.sql("create table {}.`{}` as select * from mytempTable".format(hivedb,table))
except Exception as e:
#traceback.print_exc()
error_message = e
# print str(e)
status = 'fail'
print ("{},{},{},{}".format(hivedb,table,status,error_message))
sys.exit(1)
exception
がある場合、ここでのコードのこの部分では、私はerror_message
を設定しています。
エラーがなければ、UnboundLocalError: local variable 'e' referenced before assignment
と表示されます。
エラーがなければerror_message
をNo error
に設定します。
どうすれば実現できますか?
'status = 'success''の下に' e =' No error''を入れてください。次にtry/exceptの前に定義されます。しかし、なぜこの種のセットアップが必要なのか分かりません。 – roganjosh