Skip to content

Accessing any value which is not there in dictionary is printing "DotMap()" #74

@mohan-lal

Description

@mohan-lal

After long research, this dotMap module is a lifesaver for me, in my project. Because all other JSON serialize modules end with an error during accessing values especially with multiprocessing call. This module is worth using.

I am facing the below issue with dotMap, could you please help?

    address = {'city': 'abc', 'country': 'XY', 'CountryCode': 101}
    m = DotMap(address)
    print(m.city)
    print(m.CountryCode)
    print(m.zipCode)

Output:
abc
101
DotMap()

In our input JSON, based on need only we will pass somedata(like zipCode), to reduce the load in the payload. But in my back end, in a generic way, we accessing values by doing the null check.

print(m.zipCode) if m.zipCode != ''

but, dotMap is passing 'DotMap()' string if accessing value is not there. How do I fix this? i need to pass it as empty string (''), if the accessing value not there in the dictionary. Appriciate your help on this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementneeds prIf you want to see this implemented, please submit a PR.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions