私は3つのファイルを持っています。 find_threshold_l.py、simplelogicbuffer_l.py、およびtest_find_threshold_l.py。クラスをインポートして別のファイルに使用
最初の2つのファイルを最後のファイルにインポートする必要があります。
これはsimplelogicbuffer_l.pyファイル内のクラスです:
class SimpleLogicBuffer:
def __init__(self, on_threshold):
self.on_threshold = on_threshold
self.output_state = False
def apply_input_voltage(self, value):
self.output_state = value > self.on_threshold
def is_on(self):
return self.output_state
ここfind_threshold_l.pyファイル内のコードです:
:from simplelogicbuffer_l import SimpleLogicBuffer
def find_threshold(input_value, output_state):
if output_state == True:
while output_state == True:
input_value -= 10
if input_value > SimpleLogicBuffer.DUT_Logic_Buffer.on_threshold:
continue
else:
SimpleLogicBuffer.DUT_Logic_Buffer.output_state = False
input_value
return input_value/1000
break
else:
while output_state == False:
input_value += 10
if input_value <= SimpleLogicBuffer.DUT_Logic_Buffer.on_threshold:
continue
else:
SimpleLogicBuffer.DUT_Logic_Buffer.output_state = True
input_value -= 10
return input_value/1000
break
は、ここで私は最後のファイルに書いたものです
from simplelogicbuffer_l import SimpleLogicBuffer
from find_threshold_l import find_threshold
DUT_Logic_Buffer = SimpleLogicBuffer(12500)
print("The threshold voltage is {}V".format(find_threshold(11000, DUT_Logic_Buffer.is_on())))
このコードを実行すると、エラーが発生します。
それは言った:AttributeError: type object 'SimpleLogicBuffer' has no attribute 'DUT_Logic_Buffer'
を私は少し混乱しています。 print
関数呼び出しや他の理由と関連がありますか?
ありがとうございました。
なぜ '_l'でモジュールをインポートしていますか? –
そのエラーは奇妙ですが、特にfind_thresholdというコードを見ることなく何が起きているのかを知ることは不可能です。このエラーを再現できるように[mcve]を投稿してください。 –
@Coldspeed私の間違い。ファイル名にはこの "_l"も含まれています。 –