Version 1.0
Copyright © 2023 Lowell D. Thomas
python-ini
 … powered by Python APG
Public Member Functions | Public Attributes | List of all members
python_ini.ini_file.IniFile Class Reference

Public Member Functions

def __init__ (self, values='s', debug=False)
 Ini file parser constructor. More...
 
def parse (self, fname=None, fhandle=None, fstr=None)
 Parse the input INI file. More...
 
def display_errors (self)
 Converts any errors found in the INI file syntax to a human-readable ASCII string. More...
 
def get_keys (self)
 Get a list of the global key names. More...
 
def get_values (self, key, default=None)
 Get the list of values for a global key name. More...
 
def get_sections (self)
 Get a list of the section names. More...
 
def get_section_keys (self, section)
 Get a list of key names in the named section. More...
 
def get_section_values (self, section, key, default=None)
 Get a list of values for the named key in the named section. More...
 

Public Attributes

 errors
 

Detailed Description

Definition at line 27 of file ini_file.py.

Constructor & Destructor Documentation

◆ __init__()

def python_ini.ini_file.IniFile.__init__ (   self,
  values = 's',
  debug = False 
)

Ini file parser constructor.

Parameters
valuesDetermines whether the "getter" functions", get_values() and get_section_values(), return a single value or a list of one or more values.
  • 's' (default) Only a single value is returned for a given key. If more than one value is defined for the key, only the last value is returned.
  • 'm' Keys are captured as a list of one or more values. If the same key appears more than once within a given section, the value(s) are appended to the previous list.
debugIf True, a trace of the parse is printed to stdout.

Definition at line 29 of file ini_file.py.

Member Function Documentation

◆ display_errors()

def python_ini.ini_file.IniFile.display_errors (   self)

Converts any errors found in the INI file syntax to a human-readable ASCII string.

Returns
Returns the errors display or None if none are found.

Definition at line 129 of file ini_file.py.

◆ get_keys()

def python_ini.ini_file.IniFile.get_keys (   self)

Get a list of the global key names.

Returns
Returns a list, possibly empty, of global key names.

Definition at line 139 of file ini_file.py.

◆ get_section_keys()

def python_ini.ini_file.IniFile.get_section_keys (   self,
  section 
)

Get a list of key names in the named section.

Parameters
sectionThe section name to find the key names in .
Returns
Returns a list, possibly empty, of key names.

Definition at line 182 of file ini_file.py.

◆ get_section_values()

def python_ini.ini_file.IniFile.get_section_values (   self,
  section,
  key,
  default = None 
)

Get a list of values for the named key in the named section.

Parameters
sectionThe section name to find the key in.
keyThe key name to find the list of values for.
defaultThe value to return if the section or key name is not found. The default value ignores the single- or multi-valued mode and is returned exactly as given to the user. It is the user's responsibility to supply a default that makes sense to his application.
Returns
Returns
  • default if the section or key name is not found
  • True if the key name list is empty (a default "true" flag)
  • the full list of values if the multiple values switch, "m", is set in the constructor
  • the last name in the list if the single value switch, "s", is set in the constructor

Definition at line 193 of file ini_file.py.

◆ get_sections()

def python_ini.ini_file.IniFile.get_sections (   self)

Get a list of the section names.

Returns
Returns a list, possibly empty, of section names.

Definition at line 173 of file ini_file.py.

◆ get_values()

def python_ini.ini_file.IniFile.get_values (   self,
  key,
  default = None 
)

Get the list of values for a global key name.

Parameters
keyThe name of the key to get values for.
defaultThe value to return if the key name is not found. The default value ignores the single- or multi-valued mode and is returned exactly as given to the user. It is the user's responsibility to supply a default that makes sense to his application.
Returns
Returns
  • default if the key name is not found
  • True if the key name list is empty (a default "true" flag)
  • the full list of values if the values switch, "m"(multiple), is set in the constructor
  • the last name in the list if the values switch, "s"(single), is set in the constructor

Definition at line 148 of file ini_file.py.

◆ parse()

def python_ini.ini_file.IniFile.parse (   self,
  fname = None,
  fhandle = None,
  fstr = None 
)

Parse the input INI file.

Parses the ini file, input as a file name, file handle or string. At least one of fname, fhandle or fstr must be supplied. If more than one, the first non-None value of fname, fhandle or fstr in that order is accepted. If none are supplied an Exception is raised.

Parameters
fnameThe name of the ini file to parse.
fhandleA handle to an open ini file.
fstrThe ini file as a string.

Definition at line 75 of file ini_file.py.

Member Data Documentation

◆ errors

python_ini.ini_file.IniFile.errors

Definition at line 44 of file ini_file.py.


The documentation for this class was generated from the following file:
Python APG, Version 1.0, is licensed under the 2-Clause BSD License,
an Open Source Initiative Approved License.