2014-01-07 6 views
0

IPKISS라는 잘 알려지지 않은 프레임 워크를 사용하고 있습니다. 잘하면, 이것은 중요하지 않습니다.Python 상속시 오류가 발생했습니다.

from ipkiss.all import *  

class ElectrodePair(Structure): 
    """An electrode component to be used for a PPLN design.""" 

    __name_prefix__ = "ELECTRODE_PAIR" 

    width = PositiveNumberProperty(required = True) 
    height = PositiveNumberProperty(required = True) 
    seperation = PositiveNumberProperty(required = True) 

    lay1 = Layer(number = 1, name = "boundaries") 

    def define_elements(self, elems): 
     left = ShapeRectangle(center = (-self.seperation*0.5,0.), box_size = (self.width, self.height)) 
     right = ShapeRectangle(center = (self.seperation*0.5,0.), box_size = (self.width, self.height)) 

     elems += Boundary(layer = self.lay1, shape = left) 
     elems += Boundary(layer = self.lay1, shape = right) 
     return elems 



class ElectrodeStructure(ElectrodePair): 
    """An array of electrodes.""" 

    __name_prefix__ = "ELECTRODE_STRUCTURE" 

    amount = PositiveNumberProperty(required = True) 
    spacing = PositiveNumberProperty(required = True) 

    def define_elements(self, elems): 
     electrodePair = ElectrodePair.__init__(self) 
     elems += ARefX(reference = electrodePair, origin = (0,0), period_1d = self.spacing, n_o_periods_1d = self.amount) 
     return elems 



def main(): 
    FILE_NAME = "ElectrodeArray.gds" 
    electrodeArray = ElectrodeStructure(amount = 10, height = 100., seperation = 20, spacing = 10., width = 2.) 

    electrodeArray.write_gdsii(FILE_NAME) 


if __name__ == "__main__": 
    main() 

나는 왜 이것이 오류인지 알지 못합니다. 오류 : 그것이 내가 내 인수를 통과 한 방법에 행복하지 않다 것처럼 것 같다

File "/usr/local/lib/python2.7/dist-packages/IPKISS-2.4_ce-py2.7.egg/ipcore/properties/initializer.py", 
line 327, in __init__ raise IpcoreAttributeException("Required property '%s' is not found in keyword arguments of '%s' initialization." % (p, str(type(self)))) 
ipcore.exceptions.exc.IpcoreAttributeException: Required property 'amount' is not found in keyword arguments of '<class '__main__.ElectrodeStructure'>' initialization. 

, 내가 물건의 힙을 시도하고이 동작하지 않습니다. 조언을 많이 주시면 감사하겠습니다.

나는이 오류가 electrodePair = ElectrodePair.__init__(self) 일 것으로 생각됩니다.

감사합니다.

+0

예, ElectrodePair 초기화 프로그램에서 금액을 지정해야합니다. – hd1

답변

0
class ElectrodeStructure(ElectrodePair): 
    [...] 

    def define_elements(self, elems): 
     electrodePair = ElectrodePair.__init__(self) 
     [...] 

여기에 잘못된 것입니다. __init__ 함수를 ElectrodeStructure에 정의하지 않았 으면 수퍼의 __init__이 이러한 인수 (예 : amount을 포함하여 오류가 없음)와 함께 호출되고 있습니다.

define_elements에서 오류를 일으키는 인수를 전달하지 않는 경우를 제외하고 __init__을 다시 호출합니다. 또한

,이 사항 :
 electrodePair = ElectrodePair.__init__(self) 

electrodePairElectrodePair.__init__(self)반환 값을 (가능성이 None)에 할당된다. 나는 당신이 다음과 같은 것을 더 원한다고 생각합니다 :

 electrodePair = ElectrodePair(amount=1, etc.) 

그것은 당신이 상속이 아닌 구성을 원하는 것처럼 보입니다. 서브 클래스를 적절한 __init__ 함수 (@volcano가 설명하는대로)로 초기화하거나, 그냥 상속하지 않고 ElectrodePair 클래스 멤버를 만들 수 있습니다.

1

당신은, 당신의 ElectrodeStructure 클래스에 메소드를 __init__ 추가하는이 - @ HD1이 지적한 것처럼 - 설정할 수 있습니다

class ElectrodeStructure(ElectrodePair): 
    def __init__(self, amount): 
     ElectrodePair.__init__(self) 

잘못 init__ 당신이 .__ ElectrodePair를 호출하는 방법을, 클래스에서 ElectrodeStructure .__ init__의 부재에서부터 전자는 자동으로 호출됩니다

편집 : 나는 NotI을했습니다 것들의

커플 다시 읽으면 ced - 클래스를 상속 한 다음 클래스 메서드 내에서 부모 클래스의 개체를 만듭니다. 당신이 main()의 새로운 ElectrodeStructure, 당신은 keword 인수를 전달하고 만들 때 뭔가

관련 문제