못하도록 막는 편이 좋다. 매핑에 어떠한 변경이라도 생기면 실제 물리적인 디바이스와 일치하
지 않게 되기 때문이다.
types
모듈은
MappingProxyType
이라는 래퍼 클래스를 제공해서, 원래 매핑의 동적인 뷰
이긴 하지만 읽기 전용인
mappingproxy
객체를 반환한다. 따라서 원래 매핑을 변경하면
mappingproxy
에 반영되지만,
mappingproxy
를 직접 변경할 수는 없다. [예제
3
-
10
]은 이를
사용하는 방법을 간략히 보여 준다.
예제
3-10
dict
에서 읽기 전용
mappingproxy
객체를 생성하는
MappingProxyType
>>> from types import MappingProxyType
>>>
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.