[python] __dict__와 __globals__의 관계

Shadis·2026년 4월 3일

python

목록 보기
13/13

__dict__

__dict__는 module, class, instance 각각이 가지고 있는 객체들을 저장하고 있는 special variable이다.

  1. module의 __dict__
    module에 정의된 전역변수, 함수, 객체 등

  2. class의 __dict__
    class의 property, method

  3. instance의 __dict__
    instance의 property

__globals__

method와 함수는 실행 중에 module의 전역변수에 접근해야 하는 경우가 있다. 그래서 method와 함수는 module의 __dict__를 가리키는 __globals__ special variable을 가지고 있다.

profile
HGU 20 김민석

0개의 댓글