Skip to content

Instantly share code, notes, and snippets.

@rameshkrishna
Created May 15, 2020 07:49
Show Gist options
  • Save rameshkrishna/f909eee623f75b5b327f5ca68b0238b9 to your computer and use it in GitHub Desktop.
Save rameshkrishna/f909eee623f75b5b327f5ca68b0238b9 to your computer and use it in GitHub Desktop.
Dict Without Quotes Python
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