Created
September 27, 2015 07:14
-
-
Save csaez/1b33a76b3843c1845095 to your computer and use it in GitHub Desktop.
Stupid workaround to set variables programmaticaly in the main namespace while working with jedi/rope autocomplete.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _getConstants(): | |
return {"FOO": "foo", "BAR": "bar", "BAZ": "baz"} | |
def _updateConstants(): | |
import os | |
# assemble code | |
code = "# This code is automatically generated by constants.py\n\n" | |
for k, v in _getConstants().iteritems(): | |
code += "{0} = '{1}'\n".format(k, v) | |
# diff | |
filepath = os.path.join(os.path.dirname(__file__), "_constants.py") | |
with open(filepath) as fp: | |
old_code = fp.read() | |
if old_code != code: | |
# update | |
with open(filepath, "w") as fp: | |
fp.write(code) | |
if __name__ != "__main__": | |
_updateConstants() | |
from _constants import * |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment