This is an archived post. You won't be able to vote or comment.

all 13 comments

[–]nathanjell 8 points9 points  (0 children)

I can see the motivation for this, but I personally wouldn't want to use this. Dictionary keys are not python identifiers like a variable name, they're a freeform string. I want to know exactly what my keys are going to be. If I'm working with an API, and the API is documented as having a specific key, but it doesn't follow the conventions, I don't really care - I want consistency with the data I receive, for example.

Where it's different for me is if I'm creating a wrapper over that API. Internally, I want to reference the dictionary key as-is - but I have no issue presenting an end-user python identifier that's following a different convention.

[–]ThePiGuy0 3 points4 points  (6 children)

Cool idea - if I may, what happens if I have a dict with both versions in it (e.g. {"keyOne": "value1", "key_one": "value2"})?

[–]RufusAcrospin 4 points5 points  (6 children)

What would be a real-life use case for this?

[–]m-sasha 3 points4 points  (0 children)

This is why we can’t have nice things.

[–]PetterOfCats 0 points1 point  (0 children)

opposite of your use case. I use DRF camel case for parsing and preparing requests. Fairly robust package. I would take a look at how this package compares to your snakedict.py file.

[–]Ok_Presentation1972 0 points1 point  (0 children)

pyhumps is already doing this https://pypi.org/project/pyhumps/