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

Support for semicolon based comments #79

Closed
gau1991 opened this issue Dec 18, 2014 · 3 comments
Closed

Support for semicolon based comments #79

gau1991 opened this issue Dec 18, 2014 · 3 comments

Comments

@gau1991
Copy link

gau1991 commented Dec 18, 2014

Now PHP uses semicolon separted comments it its ini file. When I am trying to read php.ini file, I am getting error

>>> config = ConfigObj('/etc/php5/fpm/php.ini')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/dist-packages/configobj.py", line 1229, in __init__
    self._load(infile, configspec)
  File "/usr/local/lib/python3.4/dist-packages/configobj.py", line 1318, in _load
    raise error
configobj.ConfigObjError: Parsing failed with several errors.
First error at line 3.
@EliAndrewC
Copy link
Member

Adding an option to the ConfigObj class to specify the character(s) which begin a comment seems like a valid and useful feature. To be honest I'm not sure when the next time we'll be doing any major configobj work will be, but we can definitely tackle this when that happens if no one makes a pull request before then.

In the meantime, a workaround you could use would be to do something really hacky like

import re
from StringIO import StringIO
with open('/etc/php5/fpm/php.ini') as f:
    file_contents = re.sub('^;', '#', f.read())
config = ConfigObj(StringIO(file_contents))

but I understand that you may want to avoid this kind of hackery.

@gepd
Copy link

gepd commented Oct 15, 2016

I've a file with ';' as market comment, I set the COMMENT_MARKERS with ['#', ';'] and when I write in the file, it ends with both markers

Ex. Initial comment:

; Comment Line 1
; Comment Line 2

After write in file:

# ; Comment Line 1
# ; Comment Line 2

I need to set both markers because some files I'm working with, starts with '#' and others ';'

@jhermann
Copy link
Collaborator

There are explicit tests for that, so your code does things differently than the test, or you use wrong versions. Check both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants