[docs] Bug report

Diego Latella dg.latella at gmail.com
Fri Mar 28 21:31:50 CET 2014


I should like to report a bug on the module 'configparser.py' 
Python version: 3.4.0 run on Mac os 10.6.8

    ### Error in 'str' name and 'str' function
    def _write_section(self, fp, section_name, section_items, delimiter):
        """Write a single section to the specified `fp'."""
        #fp.write("[{}]\n".format(section_name))
        str = "[{}]\n".format(section_name)
        fp.write(str)
        for key, value in section_items:
            value = self._interpolation.before_write(self, section_name, key,
                                                     value)
            if value is not None or not self._allow_no_value:
                value = delimiter + str(value).replace("\n", "\n\t")
            else:
                value = ""
            fp.write("{}{}\n".format(key, value))
        fp.write("\n")
    
Proposed correction:
    ### Correction made by D. Latella 28/3/2014
    def _write_section(self, fp, section_name, section_items, delimiter):
        """Write a single section to the specified `fp'."""
        #fp.write("[{}]\n".format(section_name))
        strng = "[{}]\n".format(section_name)
        fp.write(strng)
        for key, value in section_items:
            value = self._interpolation.before_write(self, section_name, key,
                                                     value)
            if value is not None or not self._allow_no_value:
                value = delimiter + str(value).replace('\n', '\n\t')
            else:
                value = ""
            fp.write("{}{}\n".format(key, value))
        fp.write("\n")

This is the code to test bug:

import os
import configparser

def get_preferences_from_file():
    config = configparser.ConfigParser()
    print(config.sections())
    if not os.access('board.ini',os.F_OK):
        # no .ini file yet, so make one
        config['DEFAULT'] = {'font':'Arial',
                             'size':'12'}
        # Writing our configuration file to 'raven.ini'
        with open('board.ini', 'w') as configfile:
            config.write(configfile)
    config.read('raven.ini')
    print('>>>>',config.sections())
    font = config['DEFAULT']['font']
    size = config['DEFAULT']['size']
    return font, size

if __name__ == '__main__':
    fs = get_preferences_from_file()
    print(fs)

Best wishes
Diego Latella
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20140328/220d30d0/attachment.html>


More information about the docs mailing list