2017-06-10 1 views
0

私は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関数呼び出しや他の理由と関連がありますか?

ありがとうございました。

+2

なぜ '_l'でモジュールをインポートしていますか? –

+0

そのエラーは奇妙ですが、特にfind_thresholdというコードを見ることなく何が起きているのかを知ることは不可能です。このエラーを再現できるように[mcve]を投稿してください。 –

+0

@Coldspeed私の間違い。ファイル名にはこの "_l"も含まれています。 –

答えて

0

DUT_Logic_Buffer_1test_find_threshold_lでご利用いただけますが、SimpleLogicBufferには属性がありませんDUT_Logic_Buffer_1であるため、エラーが発生します。このエラーを解決するには、find_thresholdの値をSimpleLogicBuffer.DUT_Logic_Buffer_1.on_thresholdの代わりに直接渡すか、直接次のようにすることができます。SimpleLogicBuffer(some_value).on_threshold

+0

ありがとうございます。とにかく、test_find_threshold.pyファイルでDUT_Logic_Buffer_1を初期化できますか? –

+0

インスタンスを引数として渡します。 – SH7890

関連する問題