यहां मैंने जो भी उपयोग किया है। extended_get
विधि है जो आपको चाहिए - यह पदानुक्रमित वर्गों का समर्थन करता है।
import re
import io
import ConfigParser
class ZendConfigParser(ConfigParser.ConfigParser):
def extended_get(self, section, key):
if self.has_option(section, key):
return self.get(section, key)
else:
orig_section, parent_section = self._get_orig_section(section)
if orig_section != None:
if self.has_option(orig_section,key):
return self.get(orig_section,key)
else:
return self.extended_get(parent_section,key)
else:
return None
def _get_orig_section(self, zend_section):
orig_section = None
parent_section = None
for section in self.sections():
if re.search(r'^[ \t]*' + zend_section + '\\b', section) != None:
orig_section = section
#look for a parent section
match = re.match(r'\w+[ \t]*:[ \t]*(\w+)$', section)
if match != None:
parent_section = match.groups()[0]
break
return (orig_section, parent_section)
config = ZendConfigParser()
config.read(file)
print(config.extended_get('production', 'database.params.host'))
जानकारी के लिए धन्यवाद। दुर्भाग्य से यह मेरे लिए एक मास्टर फ़ाइल रखने की व्यावसायिक आवश्यकता के कारण काम नहीं करेगा जिसे कई प्रोग्रामिंग भाषाओं में पार्स किया जाएगा। ऐसा लगता है कि मुझे खुद को लागू करने की आवश्यकता होगी। – Maascamp
मास्कैम्प: क्या आप सफल हुए? मेरे पास एक ही स्थिति है ... – xvga
हां, मैंने अपनी आवश्यकताओं को पूरा करने के लिए एक लागू किया (Zend_Config_Ini शैली) और जहां संभव हो पाइथन देशी प्रकारों में परिवर्तित हो जाता है। यहां देखें [https://bitbucket.org/maascamp/pyconfigini ](https://bitbucket.org/maascamp/pyconfigini)। आशा करता हूँ की ये काम करेगा। – Maascamp