python-mote::call instance-method from class-method

Today lolol·2020년 8월 12일
0

python

목록 보기
1/2

3가지 종류의 메서드가 오리라..

파이썬에서는 3가지 종류의 메서드가 있다는 것을 알 것 이다.

1. instance method
2. class method
3. static method

그 중에서 class method에서 instance method를 호출할 수 없다는 것을 알고 있는가?

TypeError: get_href_from_parent() missing 1 required positional argument: 'child_elem'

나는 위와 같은 에러와 당면했다.
당연히 매개변수는 잘주었다.

...
@classmethod
    def get_href(cls, child_elem: any) -> str:
        _href = child_elem.get_attribute(cls.HREF_EXPR)
        if not bool(_href):
            _href = cls.get_href_from_parent(child_elem)
        return _href
        
def get_href_from_parent(self, child_elem: any) -> str:
	...

엥? 당연히 매개변수 하나 아니냐?

그래서 찾은 방법은 그냥 class method -> class method 호출.

profile
working making doing makes us 🤖

0개의 댓글