dnnlib中EasyDict类的用法

 

函数最后->Any是函数返回值的注释

class EasyDict(dict):
    """Convenience class that behaves like a dict but allows access with the attribute syntax."""

    def __getattr__(self, name: str) -> Any:
        try:
            return self[name]
        except KeyError:
            raise AttributeError(name)

    def __setattr__(self, name: str, value: Any) -> None:
        self[name] = value

    def __delattr__(self, name: str) -> None:
        del self[name]

里面的三个magic method可以看别的笔记

posted @ 2022-09-13 22:38  Tomorrow1126  阅读(462)  评论(0)    收藏  举报