May be it is a common question, but I am new in python!
I am working on some libraries that handle json queries and asked myself if there is some best practice to avoid hard-coding tons of json keys like:
# just an example..
var1 = response.json()["ACRI"]["message"]["title"]
var2 = response.json()["ACRI"]["message"]["content"]
var3 = response.json()["ACRI"]["message"]["meta"]["timestamp"]
when I saw it, it didn't likes me and I created a class with constants like:
class _const:
class headers:
X_Auth_Token = "X-Auth-Token"
X_Username = 'X-Username'
X_Password = 'X-Password'
class params:
ID = "DocumentID"
Symbols = "Symbols"
ACRICode = "ACRICode"rketSegmentID"
entries = "entries"
depth = "depth"
date = "date"
meta = "meta"
timestamp = "timestamp"
message = "message"
# ...
Is that a good practice? Is there something I don't understanding about python compiler?
Thanks
edit: I'm facing performance and/or memory consumption best practices especially