-
-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accessing any value which is not there in dictionary is printing "DotMap()" #74
Comments
So it looks like you don't want dynamic child creation. To turn that off, you need to use the constructor with
which outputs:
That's the best you can do with the code you've listed. If you want a check, you would need to do:
output:
|
Thanks for responding. Is there any way to set the last element as ""(empty) instead DotMap() by writing wrapper class to DotMap class. print(m.address.zipCode.zip1) # assign with ''(empty string) if the zip1 is not there in dictionary. I tried this, it does not work. It makes parent key itself ''(empty)
|
I'm sure there is a way to turn However, to be honest, it sounds to me like the real culprit here is your calling code. I think it makes much more sense to make your calling code more robust to handle the case where the value isn't there than to try to subclass or add a new feature to |
The new design would be really helpful for me. Please let me know once the redesign approved. I completely agreed with you, on our side code practice. Currently, we are using JSON serialize function which is copied in this stack overflow question https://stackoverflow.com/questions/65876256/json-serialized-object-gives-error-with-multiprocessing-calls-typeerror-xxx-o (This question is asked by me). When I take over this application maintenance and enhancement, they already using this functionality to access as dot notation elements and this function will give an empty string "", if that value is not present. Based on this behavior, they have used it in thousands of places in hundreds of documents. Unfortunately, I can't change it everywhere, that's why I am looking to leverage the same behavior(if the value does not present return ""). The problem with this function I used in my project is, not supporting multiprocessing (as mentioned in the stack overflow question). After a lot of research, I found your module is working pretty much with my project. Your module is working very well and supporting parallel processing able to improve performance by 50% on positive cases(if all dict values present). For this negative scenario, seeking help from you. Thanks. |
Just to be clear: I won't be writing the new Unfortunately, I've given you all the help I can give. This is a free open source library that I'm simply maintaining because of its popularity. The reality is, I personally stopped using Python regularly long ago and have moved almost entirely to Go. |
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?
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.
The text was updated successfully, but these errors were encountered: