ConfigParser and .ini files
Ivan Van Laningham
ivanlan at callware.com
Fri Jan 21 13:04:33 EST 2000
More information about the Python-list mailing list
Fri Jan 21 13:04:33 EST 2000
- Previous message (by thread): ConfigParser and .ini files
- Next message (by thread): ConfigParser and .ini files
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi All-- "Fred L. Drake, Jr." wrote: > > super_banane at yahoo.com writes: > > The ConfigParser class in the default Python libraries > > does not support comments given on the value lines, separated > > by a semicolon, such as: > > > > [Section] > > keyword = value ; put your comments here > > You're right, it doesn't. > Does anyone know of a *real* specification for the .ini format? I > didn't know this was allowed. > The spec is how Windows treats .ini files. ... [snip] > These should really be separated, because what most people want is a > conventional .ini file parser. Yup. That's what I'm looking for this morning! > Anyway, I've attached a patch that allows ConfigParser to strip out > ';' comments from .ini-style entries (using '=' instead of ':' as the > value separator); RFC822-style entries should *not* be affected. I > think this is closer to what you're looking for. > I can check this in if this is the right approach. I'm still not > happy with the overloaded syntax, but this might be closer to getting > the syntaxes properly implemented. People should tell me if this is > really the right thing to do, and if it breaks anything. > I applied the patch, hoping it would help with my problem, but it didn't. Basically, what I'm seeing is two things: 1) Section headers of the form "[Button States]" come up as ParsingError because of the whitespace. I read the regex for the headers as allowing whitespace in the header, so what's going on here? Here's the regex: __SECTCRE = re.compile( r'\[' # [ r'(?P<header>[-\w]+)' # `-', `_' or any alphanum r'\]' # ] ) Not being a regex guru (not even an acolyte), I'm probably unqualified to evaluate it. What should this be to allow whitespace in section names? [*lots* of .ini files have whitespace in the section names. ...] 2) The ParsingError lists the lines it thinks are bad at the end of the run, but they come up like this on the listing: [line 5]: '[Button States]\012' [line 23]: '[CallWare Archive]\012' Now, is this because ConfigParser thinks it's on UNIX, because it treats everything as a UNIX file, because it is not expecting the '\r\n' combination, or because it's broken? <patiently-awaiting-enlightenment>-ly y'rs, Ivan ---------------------------------------------- Ivan Van Laningham Callware Technologies, Inc. ivanlan at callware.com ivanlan at home.com http://www.pauahtun.org See also: http://www.foretec.com/python/workshops/1998-11/proceedings.html Army Signal Corps: Cu Chi, Class of '70 Author: Teach Yourself Python in 24 Hours ----------------------------------------------
- Previous message (by thread): ConfigParser and .ini files
- Next message (by thread): ConfigParser and .ini files
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list