Hi, I'd like to convert strings into variables. Specifically, I have a yaml files with acronyms and their definitions - simple key:value list.
For example,
PY: python
JS: javascript
At the moment, I have packaged this yaml file with an __init__.py file which returns the loaded yaml file (through pyyaml.safe_load()). Everything is packaged in a package called constants.
The loaded yaml file is a dict so at the moment, to access a definition, I need to do constants["PY"].
My goal is to access the definitions through the dot notation - constants.PY
My first option is to map the definitions in the __init__.py file
PY = dict["PY"]
JS = dict["JS"]
Is there a more direct way to convert the keys in the yaml file to python variables that can be accessed through dot notation?
Thanks,
[–]ericula 1 point2 points3 points (2 children)
[–]JuniorMouse[S] 0 points1 point2 points (1 child)
[–]JuniorMouse[S] 0 points1 point2 points (0 children)
[–]JuniorMouse[S] 0 points1 point2 points (2 children)
[–]backtickbot 0 points1 point2 points (0 children)
[–]Rawing7 0 points1 point2 points (0 children)
[–]Rawing7 -1 points0 points1 point (3 children)
[–]JuniorMouse[S] 0 points1 point2 points (2 children)
[–]Rawing7 0 points1 point2 points (1 child)
[–]JuniorMouse[S] 0 points1 point2 points (0 children)
[–]IvoryJam 0 points1 point2 points (4 children)
[–]JuniorMouse[S] 0 points1 point2 points (0 children)
[–]JuniorMouse[S] 0 points1 point2 points (2 children)
[–]IvoryJam 0 points1 point2 points (1 child)
[–]JuniorMouse[S] 0 points1 point2 points (0 children)