473,382 Members | 1,329 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Comments in ConfigParser module

Hi list:

I have run across a situation with ConfigParser Module. It refers to
the comments in the configuration filed. According to the
http://docs.python.org/dev/lib/module-ConfigParser.html it states that
lines starting with "#" and ";" are ignored.
So lines like:
; comment
# comment
are considered comments. So far so good.

The module also allows the comments to appear in the same line as the
"name = value" constructs. The only difference being that this is only
possible with ";" and not with "#" character. I did not see this in the
documentation but this is how it is behaving.
So while the following line takes the comment as a comment.
*name = value ; comment*
the next line does not result in the same behavior.
*name = value # comment*
the name element would have "value # comment" as its value, when what I
really want is for "comment" to be taken as a comment.

QUESTION...So the question is:
Can you use "#" and ";" as comment characters? and if so why does the
"#" not apply for the same situations as the ";"? I'm working with fc7
(I synced it sometime last week) and python 2.5 (r25:51908, Feb 13 2007,
09:13:20)

Any comment greatly appreciated....
Just for reference:
On the RFC 822 <http://www.faqs.org/rfcs/rfc822.html(a document
referenced in the documentation) there is a mention of ";" being used as
comment character but not necessarily at the beginning of the line.
So anything that comes after the ";" is ignored.
name = value ; comment (";comment" would be ignored)

Apr 6 '07 #1
4 3966
Joel Andres Granados wrote:
Hi list:
Any comment greatly appreciated....
Very clever.
Apr 6 '07 #2
Joel Andres Granados wrote:
The module also allows the comments to appear in the same line as the
"name = value" constructs. The only difference being that this is only
possible with ";" and not with "#" character. I did not see this in the
documentation but this is how it is behaving.
Yes, it's not documented. There is only a comment in the source code:

# ';' is a comment delimiter only if it
follows
# a spacing character

I think it's either a bug in the code or in the documentation.
QUESTION...So the question is:
Can you use "#" and ";" as comment characters? and if so why does the
"#" not apply for the same situations as the ";"?
If you follow the documentation, comments are ONLY allowed to start a
line.
The actual implementation discards any text following a <space>;
sequence.
Just for reference:
On the RFC 822 <http://www.faqs.org/rfcs/rfc822.html(a document
referenced in the documentation) there is a mention of ";" being used as
comment character but not necessarily at the beginning of the line.
RFC822 uses ";" to include comments in the syntax rules, not for
comments in the actual message headers (parenthesis are used there).

--
Gabriel Genellina

Apr 7 '07 #3
Joel Granados wrote:
>

On 4/6/07, *James Stroud* <js*****@mbi.ucla.edu
<mailto:js*****@mbi.ucla.edu>wrote:

Joel Andres Granados wrote:
Hi list:
Any comment greatly appreciated....

Very clever.
--
http://mail.python.org/mailman/listinfo/python-list
<http://mail.python.org/mailman/listinfo/python-list>
clever ???
Well I would expect that the ";" character to behave the same way that
the "#", as they are both characters that come before a comment. But it
doesn't. So I'm missing something here. Why is the different behavior
clever?

--
Joel Andrés Granados
MedellÃ*n Colombia
--
jg******@eafit.edu.co <mailto:jg******@eafit.edu.co>
jo***********@ieee.org <mailto:jo***********@ieee.org>
I was referring to his asking for "comments" in a post about "comments".
I thought this was a clever way to conclude. I have no idea why the
behavior of the module is the way it is. Seems like a bug to me, but I
have not read the official .ini file specification, so I'm not sure its
working correctly.

Cheers,

James
Apr 9 '07 #4
En Sun, 08 Apr 2007 06:17:46 -0300, Joel Granados
<jo***********@gmail.comescribió:
On 7 Apr 2007 13:19:06 -0700, Gabriel Genellina <ga*******@yahoo.com.ar>
wrote:
>>
Joel Andres Granados wrote:
The module also allows the comments to appear in the same line as the
"name = value" constructs. The only difference being that this is
only
possible with ";" and not with "#" character. I did not see this in
the
documentation but this is how it is behaving.

Yes, it's not documented. There is only a comment in the source code:

# ';' is a comment delimiter only if it
follows
# a spacing character

I think it's either a bug in the code or in the documentation.

Yep, IMO its a weirdness in the behavior that is not documented.
It was a bit hard, but I finally found the original Windows ini-file
specification at <http://www.microsoft.com/technet/archive/wfw/2_ch6.mspx>
where you can see ; used as comment delimiter.
ConfigParser tries to handle both RFC822-like headers (with name: value,
including continuation lines, but ignoring almost everything else in the
syntax) and ini files (with ; as comments), plus some unique features like
# comments and "rem" lines removal (?). That is, it tries to cover a lot
of formats without a clear specification.
Add wrong defaults usage, and the need for SafeConfigParser, and some
other gotchas... then switch to use alternative implementations like
ConfigObj <http://www.voidspace.org.uk/python/configobj.html>

--
Gabriel Genellina

Apr 9 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Roy H. Berger | last post by:
If I want to subclass ConfigParser and changed the optionxform method to not return things in lower case wouldn't I just need the following code in my subclasss module? from ConfigParser import...
3
by: Stephen Boulet | last post by:
I'm having a bit of trouble getting my head around the ConfigParser module. I have a very simple configuration file; maybe the easiest thing to do would be to show that: ============ # Add a...
1
by: Robin Munn | last post by:
I've been loving SQLObject. The ability to set up a database connection and then completely *forget* about it and just manipulate Python objects has been great. But I'm running into a problem, and...
1
by: Pierre Quentel | last post by:
Bonjour, I am developing an application and I have a configuration file with a lot of comments to help the application users understand what the options mean I would like it to be editable,...
3
by: Sergey | last post by:
Is there an alternative to standard module ConfigParser, which can use delimitier symbol other than ":" and "=", preferaby just space? I need to parse such configs: 2:5020/758 xxxx 2:5020/794...
1
by: Alexandre CONRAD | last post by:
Hello list ! I'm using the ConfigParser module to use configuration files (what else would it be for ?). But I have a dilema: I'd like to setup multiple "update server" for my application with...
1
by: pipehappy | last post by:
Hello everyone: I came across the module ConfigParser and can use it correctly. import ConfigParser fp = open('test.cfg','w+') config = ConfigParser.ConfigParser() config.readfp(fp)...
1
by: gwillden | last post by:
Hello all, I'd like to propose the following change to ConfigParser.py. I won't call it a bug-fix because I don't know the relevant standards. This change will enable multiline comments as...
6
by: William Manley | last post by:
According to what I read in the ConfigParser module, this should work, but it doesn't. Can anyone point out what I'm doing wrong? def writeinifile ( self, FILE='P:/INI/test.ini',...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.