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_writer.IniWriter Class Reference

Public Member Functions

def __init__ (self)
 Ini file writer constructor. More...
 
def clear (self)
 Initialize or reset the writer to its constructor defaults. More...
 
def booleans (self, true=False, false=False, none=False)
 Sets the values to specify for boolean (and null) values. More...
 
def comment_tab (self, tab=None)
 Sets the column value for the tab to inline comments. More...
 
def delimiters (self, comment=False, key=False, value=False)
 Sets the delimeter values. More...
 
def section (self, name, comment=None)
 Add a section line to the INI file. More...
 
def key (self, name, varg, comment=None)
 Add a key/value line to the INI file. More...
 
def comment (self, comment=None)
 Add a comment line to the INI file. More...
 
def to_string (self)
 Convert all lines added with the section(), key() and comment() functions to a valid, formatted INI file. More...
 
def write (self, fname)
 Write the formatted INI file to a file. More...
 

Public Attributes

 errors
 

Detailed Description

Definition at line 9 of file ini_writer.py.

Constructor & Destructor Documentation

◆ __init__()

def python_ini.ini_writer.IniWriter.__init__ (   self)

Ini file writer constructor.

Note that configurable values are set to defaults.

  • True = 'true'
  • False = 'false'
  • None = 'none'
  • ; for comment delimiter
  • = for key/value delimiter
  • , for value list delimiter
  • column 40 for tab to inline comments

Definition at line 11 of file ini_writer.py.

Member Function Documentation

◆ booleans()

def python_ini.ini_writer.IniWriter.booleans (   self,
  true = False,
  false = False,
  none = False 
)

Sets the values to specify for boolean (and null) values.

Parameters
trueIf specified must be one of 'true', 'yes' or 'on', all case insensitive.
falseIf specified must be one of 'false', 'no' or 'off', all case insensitive.
noneIf specified must be one of 'none', 'null' or 'void', all case insensitive.
Returns
Raises Exception on any parameter error.

Definition at line 129 of file ini_writer.py.

◆ clear()

def python_ini.ini_writer.IniWriter.clear (   self)

Initialize or reset the writer to its constructor defaults.

Definition at line 42 of file ini_writer.py.

◆ comment()

def python_ini.ini_writer.IniWriter.comment (   self,
  comment = None 
)

Add a comment line to the INI file.

Parameters
commentA comment string. Valid comments are:
  • None (default) adds a blank line
  • ' ' empty or all white space string adds a blank line
  • string of printing ASCII characters only, char codes 32-126
Returns
Raises Exception on invalid ncomment.

Definition at line 258 of file ini_writer.py.

◆ comment_tab()

def python_ini.ini_writer.IniWriter.comment_tab (   self,
  tab = None 
)

Sets the column value for the tab to inline comments.

Parameters
tabThe column value to begin inline comments. Must be an integer tab >= 0.
Returns
Raises Exception on invalid tab value.

Definition at line 161 of file ini_writer.py.

◆ delimiters()

def python_ini.ini_writer.IniWriter.delimiters (   self,
  comment = False,
  key = False,
  value = False 
)

Sets the delimeter values.

Parameters
commentThe comment delimiter. Must be semicolon(";") or hash("#").
keyThe key/value delimiter. Must be equals("="), colon(":") or space.
valueThe delimiter between multiple key values. Must be comma(",") or space.
Returns
Raises Exception on invalid argument values.

Definition at line 175 of file ini_writer.py.

◆ key()

def python_ini.ini_writer.IniWriter.key (   self,
  name,
  varg,
  comment = None 
)

Add a key/value line to the INI file.

Parameters
nameThe key name. Must be one or more characters from the set
  • a-zA-Z0-9!$%()*+-.<>?@^_{|}~
vargThe value for the key. May be a single value or a list of values. Valid values are:
  • True
  • False
  • None
  • integer, positive or negative
  • floating point number, positive or negative
  • string
commentAn inline comment to add to the key/value line.
Returns
Raises Exception on invalid name, value or comment.

Definition at line 220 of file ini_writer.py.

◆ section()

def python_ini.ini_writer.IniWriter.section (   self,
  name,
  comment = None 
)

Add a section line to the INI file.

Parameters
nameThe section name. Must be one or more characters from the set
  • a-zA-Z0-9!$%()*+-.<>?@^_{|}~
commentAn inline comment to add to the section name line.
Returns
Raises Exception on invalid name or comment.

Definition at line 209 of file ini_writer.py.

◆ to_string()

def python_ini.ini_writer.IniWriter.to_string (   self)

Convert all lines added with the section(), key() and comment() functions to a valid, formatted INI file.

Returns
The formatted INI file as a string.

Definition at line 269 of file ini_writer.py.

◆ write()

def python_ini.ini_writer.IniWriter.write (   self,
  fname 
)

Write the formatted INI file to a file.

Calls to_string().

Parameters
fnameThe file name to write the INI file to.
Returns
Raises exceptions on file open or write errors.

Definition at line 324 of file ini_writer.py.

Member Data Documentation

◆ errors

python_ini.ini_writer.IniWriter.errors

Definition at line 44 of file ini_writer.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.