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

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

by 루시아누 하말류, 강권학
November 2024
Beginner to intermediate
1064 pages
25h 21m
Korean
Hanbit Media, Inc.
Content preview from 전문가를 위한 파이썬(2판)
450
3
클래스와 프로토콜
else:
coords = self
outer_fmt = ‘({}, {})’
components = (format(c, fmt_spec) for c in coords)
return outer_fmt.format(*components)
@classmethod
def frombytes(cls, octets):
typecode = chr(octets[0])
memv = memoryview(octets[1:]).cast(typecode)
return cls(*memv)
정리해 보면, 이번 절까지 오면서 완전히 갖춰진 객체를 구현하는 필요한 핵심적인 특별 메서
드를 몇 가지 살펴보았다.
NOTE
애플리케이션에 필요한 특별 메서드만 구현하는 편이 좋다. 클래스 사용자는 애플리케이션을 구성
하는 객체가 파이썬다운지 아닌지는 신경 쓰지 않는다.
그러나 클래스가 라이브러리의 일부분이라면 클래스 사용자가 객체를 어떻게 사용할지 예측할 수 없고, 클
래스 사용자는 여러분이 구현한 클래스가 파이썬다운 작동을 잘 지원할 거라 기대할 수도 있다.
[예제
11
-
11
]에서 구현한
Vector2d
는 객체 표현에 관련된 특별 메서드들을 설명하려고 장황
하게 구현한 예지만, 모든 사용자 정의 클래스가 따라야 하는 틀은 아니다.
다음 절에서는
Vector2d
에서 잠시 ...
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