YAMLã£ã¦ä¾¿å©ã§ããããã§ãå®ã¯ãPythonã«ã¯è¨èªä»æ§ã¬ãã«ã§ãåçã®æ©è½ãããã
config.py:
PREFIX='>>' DELIMITER='----' class ACCOUNT: id = 'username' pwd = 'password' class DETAIL: name = 'J.Luser' email = '[email protected]'
main.py:
import config ... pref = config.PREFIX delim = config.DELIMITER ... login(config.ACCOUNT.id, config.ACCOUNT.pwd) print "email is %s"%(config.ACCOUNT.DETAIL.email) ...
ã»ããï¼(ç¬)
åçã«èªã¿è¾¼ããªãã
ctx = {} exec 'import config' in ctx config = ctx['config'] print "PREFIX is '%s'"%(config.PREFIX)
ãªãã¼ãã ã£ã¦ã§ããã
reload(config)
ãã¿ã§ããããã¡ãããå®ç¨çãã©ããã¯ãããããããªããæå¤ã¨ä½¿ããããªæ°ãããã
# æ¸ãåºãã¯ã§ããªããªãã§ããããã使ãæ¹ãããã¨ãªããããããã
ãã¿ã¤ãã§ã«æ¸ãã¦ããã¨ããã¡ã¤ã«ä»¥å¤ã®ä»»æã®å ¥å(æååã¨ããã¹ããªã¼ã ã¨ã)ã§ããexec ã£ã¦ããæ¹åã§ããªãã¨ããªãã¾ãã
ãã¸ã¡ã«ãããã人ã¯ãã¡ã â PyYAML http://www.pyyaml.org/wiki/PyYAML
# ãã´ããããã£ã¦èªã¿ãããªãã