나는 지난 주 Python을 사용 해왔고 클래스 메서드에 4 개의 매개 변수를 전달할 때 문제가 발생했습니다.파이썬에서 클래스 메서드에 매개 변수를 전달할 때의 문제
def LineDepot():
x0 = None
x1 = None
y0 = None
y1 = None
line = Line()
print"Please enter starting and ending coordinates "
print"If no value is entered, then it will be assumed that the coordinate value is zero "
x0 = int(input('Enter value for initial x coordiante : '))
y0 = int(input('Enter value for initial y coordiante : '))
x1 = int(input('Enter value for end x coordiante :'))
y1 = int(input('Enter value for end y coordiante :'))
line.setLineCoordinates(x0, y0, x1, y1)
이 내가 점점 된 오류는 다음과 같습니다 I 클래스의 메서드를 호출 할 경우
다음class Line:
locx0 = 0
locy0 = 0
locx1 = 0
locy1 = 0
def __init__(self):
print'<<Line __init__()>>'
def setLineCoordinates(locx0, locy0, locx1, locy1):
self.locx0 = locx0
self.locy0 = locy0
self.locx1 = locx1
self.locy1 = locy1
def getLineCoordinatesX0():
return self.x0
def getLineCoordinatesY0():
return self.y0
def getLineCoordinatesX1():
return self.x1
def getLineCoordinatesY0():
return self.y0
은 다음과 같습니다
클래스의 방법은 그것의 클래스 내에서 정의된다 출력 : 내가 사 개 인수를 통과 할 때
940,593,210 내가 내 인생 알아 내려고 노력하는 이유, 인터프리터 내가이 5
를 전달하는 데 노력하고 연구하는 과정에서 계속하고 있음을 말해 입니다 문제.
이 문제에 대한 도움을 주시면 감사하겠습니다. 감사합니다 !!!
서식 참고 : 여기
및
이 출력됩니다. 감사! –클래스가'object'에서 상속되도록하십시오. 그렇지 않으면 오래된 스타일의 클래스를 사용하고 있으며 이는 나쁘다. – Daenyth
주목할만한 또 다른 사항 :이 함수는 classmethod가 아닌 인스턴스 메소드입니다. – Daenyth