मैं एक पायथन कॉन्फ़िगरेशन लाइब्रेरी की तलाश में हूं जो एकाधिक टेक्स्ट कॉन्फ़िगरेशन फ़ाइलों को एक ऑब्जेक्ट में जेसन की तरह मर्ज करता है।पायथन कॉन्फ़िगरेशन लाइब्रेरी
क्या किसी को भी अच्छा पता है?
मैं एक पायथन कॉन्फ़िगरेशन लाइब्रेरी की तलाश में हूं जो एकाधिक टेक्स्ट कॉन्फ़िगरेशन फ़ाइलों को एक ऑब्जेक्ट में जेसन की तरह मर्ज करता है।पायथन कॉन्फ़िगरेशन लाइब्रेरी
क्या किसी को भी अच्छा पता है?
मैं इस purpose.The विन्यास वाक्य रचना के लिए pymlconf लिखा yaml है।
उदाहरण के लिए:
कॉन्फ़िग फ़ाइलें:
#app/conf/users/sites.mysite.conf:
name: mysite.com
owner:
name: My Name
phone: My Phone Number
address: My Address
#app/conf/admin/root.conf:
server:
version: 0.3a
sites:
admin:
name: admin.site.com
owner:
name: Admin Name
phone: Admin Phone Number
address: Admin Address
#app/conf/admin/server.conf:
host: 0.0.0.0
port: 80
#../other_path/../special.conf:
licence_file: /path/to/file
log_file: /path/to/file
#app/src/builtin_config.py:
_builtin_config={
'server':{'name':'Power Server'}
}
OR:
_builtin_config="""
server:
name: Power Server
"""
तो एक लाइन के उपयोग पर नज़र डालें:
from pymlconf import ConfigManager
from app.builtin_config import _builtin_config
config_root = ConfigManager(
_builtin_config,
['app/conf/admin','app/conf/users'],
'../other_path/../special.conf')
ला रहा है config प्रविष्टियों:
# All from app/conf/users/sites.mysite.conf
print config_root.sites.mysite.name
print config_root.sites.mysite.owner.name
print config_root.sites.mysite.owner.address
print config_root.sites.mysite.owner.phone
# All from app/conf/admin/root.conf
print config_root.sites.admin.name
print config_root.sites.admin.owner.name
print config_root.sites.admin.owner.address
print config_root.sites.admin.owner.phone
print config_root.server.name # from _builtin_config
print config_root.server.version # from app/conf/admin/root.conf
print config_root.server.host # from app/conf/admin/server.conf
print config_root.server.port # from app/conf/admin/server.conf
print config_root.licence_file # from ../other_path/../special.conf
print config_root.log_file # from ../other_path/../special.conf
यह इस अपने problem.but को शामिल किया गया लगता है आप github
लिंक पर यह कांटा कर सकते हैं:
मानक कॉन्फ़िगरेशन-फ़ाइल पार्सर मानक पायथन वितरण का हिस्सा ConfigParser
है। इसके बारे में यहां सब कुछ पढ़ें: http://docs.python.org/2/library/configparser.html
यह कई फ़ाइलों का भी समर्थन करता है।
अच्छा और आसान उपयोग करने के लिए:
import ConfigParser
config = ConfigParser.ConfigParser()
config.read('example.cfg')
# Retrieve a variable
myvar = config.get("sectionName", "variableName", 0)