def GetSettings(filename, section=None, entry=None): """Returns string from a specified section in a initialization file. Parameters: filename (str): name of the initialization file section (str, optional): section containing the entry entry (str, optional): entry whose associated string is to be returned Returns: list(str, ...): If section is not specified, a list containing all section names list(str, ...): If entry is not specified, a list containing all entry names for a given section str: If section and entry are specified, a value for entry None: if not successful Example: import rhinoscriptsyntax as rs filename = rs.OpenFileName("Open", "Initialization Files (*.ini)|*.ini||") if filename: sections = rs.GetSettings(filename) if sections: section = rs.ListBox(sections, "Select a section", filename) if section: entries = rs.GetSettings(filename, section) if entries: entry = rs.ListBox(entries, "Select an entry", section) if entry: value = rs.GetSettings(filename, section, entry) if value: rs.MessageBox( value, 0, entry ) See Also: """ import ConfigParser try: cp = ConfigParser.ConfigParser() cp.read(filename) if not section: return cp.sections() section = string.lower(section) if not entry: return cp.options(section) entry = string.lower(entry) return cp.get(section, entry) except IOError: return scriptcontext.errorhander() return scriptcontext.errorhandler()
def GetSettings(filename, section=None, entry=None): """Returns string from a specified section in a initialization file. Parameters: filename = name of the initialization file section[opt] = section containing the entry entry[opt] = entry whose associated string is to be returned Returns: If section is not specified, a list containing all section names If entry is not specified, a list containing all entry names for a given section If section and entry are specied, a value for entry None if not successful Example: import rhinoscriptsyntax as rs filename = rs.OpenFileName("Open", "Initialization Files (*.ini)|*.ini||") if filename: sections = rs.GetSettings(filename) if sections: section = rs.ListBox(sections, "Select a section", filename) if section: entries = rs.GetSettings(filename, section) if entries: entry = rs.ListBox(entries, "Select an entry", section) if entry value = rs.GetSettings(filename, section, entry) See Also: """ import ConfigParser try: cp = ConfigParser.ConfigParser() cp.read(filename) if not section: return cp.sections() section = string.lower(section) if not entry: return cp.options(section) entry = string.lower(entry) return cp.get(section, entry) except IOError: return scriptcontext.errorhander() return scriptcontext.errorhandler()
def GetSettings(filename, section=None, entry=None): """Returns string from a specified section in a initialization file. Parameters: filename = name of the initialization file section[opt] = section containing the entry entry[opt] = entry whose associated string is to be returned Returns: If section is not specified, a list containing all section names If entry is not specified, a list containing all entry names for a given section If section and entry are specied, a value for entry None if not successful """ import ConfigParser try: cp = ConfigParser.ConfigParser() cp.read(filename) if not section: return cp.sections() section = string.lower(section) if not entry: return cp.options(section) entry = string.lower(entry) return cp.get(section, entry) except IOError: return scriptcontext.errorhander() return scriptcontext.errorhandler()