Skip to Content
전문가를 위한 파이썬(2판)
book

전문가를 위한 파이썬(2판)

by 루시아누 하말류, 강권학
November 2024
Beginner to intermediate
1064 pages
25h 21m
Korean
Hanbit Media, Inc.
Content preview from 전문가를 위한 파이썬(2판)
572
3
클래스와 프로토콜
❶ 클래스
A
diamond
.
py
(예제
14
-
4
)에서 가져온다.
❷ 클래스
U
diamond
모듈의 클래스
A
Root
와 무관하다.
super
().
ping
()
은 어느 메서드를 호출할까? 상황에 따라 달라진다.
LeafUA
는 클래스
U
A
를 언급한 순서대로 상속한다.
U
의 인스턴스를 만들고
ping( )
을 호출하면 다음과 같은 에러가 발생한다.
>>> u = U()
>>> u.ping()
Traceback (most recent call last):
...
AttributeError: ‘super’ object has no attribute ‘ping’
super( )
가 반환한
‘super’
객체에
ping
이라는 속성이 없다. 클래스
U
MRO
에는
U
object
가 있는데,
object
클래스에는
‘ping’
이라는 이름의 속성이 없기 때문이다.
그러나
U.ping( )
메서드가 완전히 희망이 없는 것은 아니다. 다음 실행 예를 보자.
>>> leaf2 = LeafUA()
>>> leaf2.ping()
<instance of LeafUA>.ping() in LeafUA
<instance of LeafUA>.ping() in U
<instance of LeafUA>.ping() in A
<instance of LeafUA>.ping() ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

전문가를 위한 리액트

전문가를 위한 리액트

테자스 쿠마르
고성능 파이썬(2판)

고성능 파이썬(2판)

오현석, 미샤 고렐릭, 이안 오스발트

Publisher Resources

ISBN: 9791169211772