Last active
December 30, 2015 16:09
-
-
Save vtsatskin/7853248 to your computer and use it in GitHub Desktop.
Python global and user config variables + git. The idea behind this is that you have one central place to keep config variables with the option of having user-specific variables outside of user control. Useful for working with API keys and other sensitive data. Simply put user-specific variables in config_user.py.
This file contains 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
config_user.py |
This file contains 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
secretKey = "" | |
try: | |
from config_user import * | |
except ImportError: | |
pass # Could not find user config |
This file contains 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
# Contains user-specific config variables | |
secretKey = "MY SUPER SECRET KEY" |
This file contains 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
import config | |
print "The secret key is: " + config.secretKey |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great, thanks Val! Is there a reason you put the import functionality in config.py, as opposed to in main.py?