첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

■ ReferenceType 클래스를 사용해 약한 참조를 만드는 방법을 보여준다.

 

▶ 예제 코드 (PY)

import weakref

class Apple:
    pass

apple1 = Apple()

apple1.Color = "빨강"

weakref1 = weakref.ReferenceType(apple1) # ref 별칭을 사용할 수 있다.

apple2 = weakref1()

print(apple2.Color) # 빨강

print(apple1 is apple2) # True, 두 객체는 동일하다.
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요