Skip to content
This repository has been archived by the owner on Dec 2, 2021. It is now read-only.

FrozenJSON #20

Open
xiaochuntu opened this issue May 24, 2018 · 1 comment
Open

FrozenJSON #20

xiaochuntu opened this issue May 24, 2018 · 1 comment

Comments

@xiaochuntu
Copy link

example 19-5 FrozenJSON

def __init__(self, mapping):
        self.__data = dict(mapping)  ➊

    def __getattr__(self, name):  ➋
        if hasattr(self.__data, name):
            return getattr(self.__data, name)  ➌
        else:
            return FrozenJSON.build(self.__data[name])  ➍

self.__data is a dict ,function hasattr(object, name) the first parameter is object,so hasattr(self.__data, name) always return False,so step ➌ never return . am i right?

@chinaylssly
Copy link

Yeah!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants