On Nov 27, 2019, at 12:27, Abdur-Rahmaan Janhangeer <arj.python@gmail.com> wrote:
Using 3.7, in json module of the std lib there is json.load and json.loads . I gather json.loads is more used to convert string to dict structure.
Yes, loads is to load from a string; load is used to load from a file (or file-like object).
json.load might cause (it already causes) confusions.
I’m curious what names you would use? Maybe load_string and load_file? Anyway, more explicit names might have been better, but load/loads is so well established—across other document types, and third-party modules as well as stdlib, and so on—that changing it in just one module would cause a lot more confusion than it could possibly solve, and changing it everywhere isn’t feasible. Plus, there’s decades worth of working code using these names; breaking all that code requires a really big benefit. Also, I think the other two quasi-standards out there for similar cases are much worse. Some modules have a single function that type-switches on string as contents vs. file, while others have a function that type-switches on string as pathname vs. file plus a separate fromstring function for parsing contents. That’s a lot more confusing. I frequently accidentally try to parse a pathname as an XML document, or to open a file using an XML document as a pathname, but I never make that mistake with JSON.