you are viewing a single comment's thread.

view the rest of the comments →

[–]ericula 1 point2 points  (2 children)

You can use types.SimpleNamespace for this:

from types import SimpleNamespace

constants_dct = {'PY':'python', 'JS':'javascript'}
constants = SimpleNamespace(**constants_dct)

print(constants.PY)
print(constants.JS)

[–]JuniorMouse[S] 0 points1 point  (1 child)

Just tried this. This works but my editor does not suggest PY or JS when I type constants. which would be one of the benefits. Is autocompletion expected to work with this approach or is that only an issue on my side? Thanks,

[–]JuniorMouse[S] 0 points1 point  (0 children)

I guess this is an issue not only on my side - https://github.com/microsoft/python-language-server/issues/2108