473,671 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ConfigParser - add a stop sentinel?

I am working with PythonCard in one of my apps. For its purposes, it
uses an .ini file that is passed to ConfigParser. For my app, I also
need configuration information, but for various reasons, I'd rather
use a syntax that ConfigParser can't handle.

I know I can maintain two separate configuration files, and if I have
to I will, but I'd rather avoid that, if possible, and a solution
that suits my purposes is quite straightforward . I insert a sentinel
in the ini file and modify my local ConfigParser's _read method to
stop accepting input when it encounters that value. I handle my app's
portion of the configuration myself.

This all works fine, but I was wondering whether it might be
worthwhile to add a standard stop flag in ConfigParser itself. Am I
the only one with this sort of use case? If there were a standard way
of doing this, I'd much rather use that, particularly if I ever have
reason to distribute the app elsewhere.
--
rzed

Jul 18 '05 #1
2 1697
You should probably consider NOT doing what you suggest. You
would need to do some rather extensive work so you can support
the .write method of ConfigParser. With a little ingenuity
I've been able to user ConfigParser to support some very
different and complex syntaxes on different projects. If this
won't work, just have two different (separate) files.

If you are dead set on combining these two, put your foreign
syntax lines into the file as comments. ConfigParser will
not process them, and you can have some other class extract
only the comments and parse them independently.

Regards,
Larry Bates

rzed wrote:
I am working with PythonCard in one of my apps. For its purposes, it
uses an .ini file that is passed to ConfigParser. For my app, I also
need configuration information, but for various reasons, I'd rather
use a syntax that ConfigParser can't handle.

I know I can maintain two separate configuration files, and if I have
to I will, but I'd rather avoid that, if possible, and a solution
that suits my purposes is quite straightforward . I insert a sentinel
in the ini file and modify my local ConfigParser's _read method to
stop accepting input when it encounters that value. I handle my app's
portion of the configuration myself.

This all works fine, but I was wondering whether it might be
worthwhile to add a standard stop flag in ConfigParser itself. Am I
the only one with this sort of use case? If there were a standard way
of doing this, I'd much rather use that, particularly if I ever have
reason to distribute the app elsewhere.

Jul 18 '05 #2
Larry Bates <lb****@syscono nline.com> wrote in
news:nZ******** ************@co mcast.com:

[responding to the idea of placing a sentinel in an ini file,
and modifying ConfigParser to stop receiving input when it is
encountered]:
You should probably consider NOT doing what you suggest. You
would need to do some rather extensive work so you can support
the .write method of ConfigParser. With a little ingenuity
I've been able to user ConfigParser to support some very
different and complex syntaxes on different projects. If this
won't work, just have two different (separate) files.

If you are dead set on combining these two, put your foreign
syntax lines into the file as comments. ConfigParser will
not process them, and you can have some other class extract
only the comments and parse them independently.


I'm not sure I understand what you mean about the .write method of
ConfigParser. I'm not trying to alter the *behavior* of
ConfigParser at all, just giving it an alternative end of input
(apart from EOF). And I'm not trying to replicate ConfigParser in
my own configuration stuff. If I were, I'd just use ConfigParser.

What I am doing is specifying a cluster of parameters on a single
line in a compact, comma-separated form. I can easily split each
parameter line and use the appropriate values, but it's not
something ConfigParser is designed to accommodate, as far as I can
tell.

I don't want to put them into comments (though I could, I see),
because I comment my own lines with hashmarks as well. I suppose I
could lead off with double hashmarks and just strip off the first
to get the desired effect, but it's an annoyance and it doesn't
contribute to understanding what the config file is supposed to do.
Still, as a workaround, it is something to consider.

I just can't imagine that I'm the first person in history to have
stumbled on such a use case, though. If ConfigParser would have a
way to just take in raw data line-by-line within some group
heading, that would work for this case just as well, and it seems
to me that *that* might be useful in some other applications also
.... though that's not what I'm talking about in this instance.

--
rzed

Jul 18 '05 #3

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

Similar topics

3
2621
by: Greg Krohn | last post by:
I'm trying to subclass ConfigParser so I can use a custom __read method (the custom format doesn't conform to RFC 822) when needed. Needless to say, it's not working as expected. In the following code, I bind __read_ini to __read and override __read so it can choose between __read_ini and __read_custom. But it seems that __read_custom never gets called when I expect it to aways be called. I have a feeling this has to do with me not...
1
1819
by: Martin Maney | last post by:
Summary: with batteries like these, get a longer extension cord? <transcript from interactive session> Python 2.2.1 (#1, Sep 7 2002, 14:34:30) on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from ConfigParser import ConfigParser >>> cp = ConfigParser()
2
4296
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 * class MyConfigParser(ConfigParser): def __init__(self, defaults=None): ConfigParser.__init__(self, defaults)
6
6777
by: Matthew Barnes | last post by:
I'm considering submitting a patch for Python 2.4 to allow environment variable expansion in ConfigParser files. The use cases for this should be obvious. I'd like to be able to specify something like the following in a configuration file: data_file=${HOME}/mydata.dat ....(where HOME=/home/matt) and have ConfigParser automatically expand it to:
11
4894
by: Manlio Perillo | last post by:
Regards. Since sections in CongiParser files are delimited by , why there is not an escape (and unescape) function for escaping &, characters to &amp;, &lbrack; and &rbrack; ? Thanks Manlio Perillo
10
11806
by: Terry Carroll | last post by:
It looks like ConfigParser will accept a list to be writing to the *.ini file; but when reading it back in, it treats it as a string. Example: ############################### import ConfigParser def whatzit(thingname, thing): print thingname, "value:", thing print thingname, "length:", len(thing)
1
2014
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) config.add_section('test') config.set('test', 'haha', 'hehe')
4
1864
by: Danil Dotsenko | last post by:
Wrote a little "user-friedly" wrapper for ConfigParser for a KDE's SuperKaramba widget. (http://www.kde-look.org/content/show.php?content=32185) I was using 2.4.x python docs as reference and ConfigParser.read('non-existent-filename') returns in 2.4.x One user with 2.3.x reported an error stemming from my use of len(cfgObject.read('potentially-non-existent-filename'))
4
14232
by: Phoe6 | last post by:
Hi, I have a configfile, in fact, I am providing a configfile in the format: Name: Foo Author: Bar Testcases: tct123
0
8474
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8392
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8912
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8819
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8597
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7428
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6222
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5692
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
1807
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.