私はラボテストソフトウェアに取り組んでいます。私はバックボーンステージにあります。ここでテスト変数のスローエラーをテストする
はコードです:
import sys
def main(argv):
currentTempAverage = 0;
testingPlaced = False
typeOfTesting = False
issue="False"
class labTesting(object):
def __init__(self,currentCondition,emergencyStop=0):
self.output = labLog()
Conditions = []
self.status = "OPEN"
self.beginningCondition = currentCondition
self.EndingCondition = ""
self.output.log("Testing opened")
if float(currentCondition) > float(self.beginningCondition*1.003):
issue="True"
if (issue=="True") and float(currentCondition) < float(beginningCondition*1.002):
self.output.log("YIKES!")
self.status="CLOSED"
if (emergencyStop):
self.emergencyStop = currentCondition - emergencyStop
self.output.log("stop loss")
def close(self,currentCondition):
if currentCondition > (self.beginningCondition * 1.012717049):
self.status = "CLOSED"
self.EndingCondition = currentCondition
def tick(self, currentCondition):
def showTesting(self):
testingStatus = "Entry Condition: "+str(self.beginningCondition)
self.output.log(testingStatus)
は基本的に、それはレベルをチェックしていますし、レベルが特定のポイントに達した場合 - それは問題になる可能性があるため、問題=真を。
レベルが低くなると緊急停止します。私のやり方によっては、エラーが発生します。
Traceback (most recent call last):
File "/home/DDesm/Desktop/w/labtest/testing.py", line 18, in tick
if (issue=="True") and float(currentPrice) < float(entryPrice*1.002):
UnboundLocalError: local variable 'issue' referenced before assignment
ありがとう!
あなたはこのライン 'クラスlabTesting(オブジェクト)を持っている::'メイン 'で()'とインデントがオフになっている次のようにあなたはオーバー
__init__
方法にissue
を渡すことで、これを来ることができます。 – srigここでの問題は、最初の条件が満たされない場合、変数 'issue'が定義されていないことです。 'main'に' issue = false'を書くと、その変数は 'main'関数のスコープ内にしか存在しないので、他の場所で定義されるまでその関数の外部ではアクセスできません。 – Tim
コードのインデントが不十分で、不完全です。 –