Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configparser unable to write comment with a upper cas letter #75716

Closed
philippewagniereshispeedch mannequin opened this issue Sep 20, 2017 · 6 comments
Closed

configparser unable to write comment with a upper cas letter #75716

philippewagniereshispeedch mannequin opened this issue Sep 20, 2017 · 6 comments
Labels
type-feature A feature request or enhancement

Comments

@philippewagniereshispeedch
Copy link
Mannequin

BPO 31535
Nosy @tirkarthi

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2018-09-24.15:42:26.724>
created_at = <Date 2017-09-20.16:28:22.408>
labels = ['type-feature', 'invalid']
title = 'configparser unable to write comment with a upper cas letter'
updated_at = <Date 2018-09-26.07:15:50.693>
user = 'https://bugs.python.org/philippewagniereshispeedch'

bugs.python.org fields:

activity = <Date 2018-09-26.07:15:50.693>
actor = 'philippewagnieres@hispeed.ch'
assignee = 'none'
closed = True
closed_date = <Date 2018-09-24.15:42:26.724>
closer = 'xtreak'
components = []
creation = <Date 2017-09-20.16:28:22.408>
creator = 'philippewagnieres@hispeed.ch'
dependencies = []
files = []
hgrepos = []
issue_num = 31535
keywords = []
message_count = 6.0
messages = ['302633', '325000', '325002', '325003', '326255', '326422']
nosy_count = 2.0
nosy_names = ['philippewagnieres@hispeed.ch', 'xtreak']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue31535'
versions = ['Python 3.6']

@philippewagniereshispeedch
Copy link
Mannequin Author

I create entry with this:

self.settings.set('General', 'Initial filter', 'All file (.*)')
self.settings.set('General', '# 1 => Text files (
.txt)')
self.settings.set('General', '# 2 => CSV files (.csv)')
self.settings.set('General', '# 3 => Text files (
.txt) \n')

and after writing in a file:
initial filter = All file (.*)
; 1 => text files (
.txt)
; 2 => csv files (.csv)
# 3 => text files (
.txt)

(; or # to test if differ)

It is normal or not?

Thank & Best Regards

@philippewagniereshispeedch philippewagniereshispeedch mannequin added the type-feature A feature request or enhancement label Sep 20, 2017
@tirkarthi
Copy link
Member

All config options are converted to lowercase when they are stored. You can customise this with https://docs.python.org/3/library/configparser.html#configparser.ConfigParser.optionxform. You can customize it more with https://docs.python.org/3/library/configparser.html#customizing-parser-behaviour

Note also that keys in sections are case-insensitive and stored in lowercase

>>> from configparser import ConfigParser
>>> c = ConfigParser()
>>> c["A"] = {'FOO': 'bar'}
>>> with open('example.ini', 'w') as configfile: c.write(configfile)
...
>>> with open('example.ini', 'r') as configfile: print(configfile.read())
...
[A]
foo = bar

# Don't convert to lower case

>>> d = ConfigParser()
>>> d.optionxform = str
>>> d["A"] = {'FOO': 'bar'}
>>> with open('example_case.ini', 'w') as configfile: d.write(configfile)
...
>>> with open('example_case.ini', 'r') as configfile: print(configfile.read())
...
[A]
FOO = bar

Hope this answers your question. Feel free to close this if it's clear.

Thanks

@tirkarthi
Copy link
Member

Ah sorry, didn't notice it was about comments. It seems config.optionxform = str has no effect on comments.

Thanks

@tirkarthi
Copy link
Member

Ah my bad again. The config.optionxform = str does the trick. I was using an older object.

from configparser import ConfigParser

config = ConfigParser(allow_no_value=True)
config.optionxform = str
config.add_section('default_settings')
config.set('default_settings', '; comment HERE')

with open('example_case.ini', 'w') as configfile: config.write(configfile)
with open('example_case.ini', 'r') as configfile: print(configfile.read())

Thanks

@tirkarthi
Copy link
Member

All config options including comment are converted to lowercase when they are stored. You can customize this behavior using https://docs.python.org/3/library/configparser.html#configparser.ConfigParser.optionxform . You can also refer to https://docs.python.org/3/library/configparser.html#customizing-parser-behaviour for more customization. I am closing this as not a bug as part of triaging. Feel free to reopen this if needed.

Thanks for the report Philippe!

@philippewagniereshispeedch
Copy link
Mannequin Author

Thank for your support.

Sorry I have no time to give you an answer and work on with Python, but
I have understand the solution.

Best Regards

Philippe Wagnières
Chalamont 6
1400 Yverdon-les-Bains
Suisse
tel.: +41 76 367 27 43

Le 24.09.2018 à 17:42, Karthikeyan Singaravelan a écrit :

Karthikeyan Singaravelan <tir.karthi@gmail.com> added the comment:

All config options including comment are converted to lowercase when they are stored. You can customize this behavior using https://docs.python.org/3/library/configparser.html#configparser.ConfigParser.optionxform . You can also refer to https://docs.python.org/3/library/configparser.html#customizing-parser-behaviour for more customization. I am closing this as not a bug as part of triaging. Feel free to reopen this if needed.

Thanks for the report Philippe!

----------
resolution: -> not a bug
stage: -> resolved
status: open -> closed


Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue31535\>


@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant