Created
May 15, 2020 07:49
-
-
Save rameshkrishna/f909eee623f75b5b327f5ca68b0238b9 to your computer and use it in GitHub Desktop.
Dict Without Quotes Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DictWithoutQuotedKeys(dict): | |
def __repr__(self): | |
s = "{" | |
for key in self: | |
s += "{0}:".format(key) | |
# if isinstance(self[key], str): | |
# # String values still get quoted | |
# s += "\"{0}\", ".format(self[key]) | |
# if isinstance(self[key], int): | |
# # String values still get quoted | |
# s += "\'{0}\', ".format(self[key]) | |
if isinstance(self[key], dict): | |
# Apply formatting recursively | |
s += "{0}, ".format(DictWithoutQuotedKeys(self[key])) | |
else: | |
# Quote all the values | |
s += "\'{0}\', ".format(self[key]) | |
if len(s) > 1: | |
s = s[0: -2] | |
s += "}" | |
return s | |
#Used while sending request to shopify | |
#https://stackoverflow.com/a/61814243/13547176 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment