473,395 Members | 1,696 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,395 software developers and data experts.

Configuration Files

Hi,

I'm interested in creating a large number of configuration files which I
have no experience doing in python. The fields will be static for the most
part. But design changes and I might want to add new fields in the future..

My question is - whats the best module for creating, reading, and editing
these files(something like an INI)? I want it to be powerful,
yet simple and minimalistic, not requiring a huge amount of overhead.

I've heard of xml, and have seen it used in both html fashion, and
likewise, without any tags at all- just spaces in between entries; why is
this? CSV is another thing I've seen thrown around on online
documentation. Whats the difference between the two, and which one should
I use(if either)?

-thanks in advance
Jul 18 '05 #1
5 1461
Aaron wrote:
Hi,

I'm interested in creating a large number of configuration files which I have no experience doing in python. The fields will be static for the most part. But design changes and I might want to add new fields in the future..
My question is - whats the best module for creating, reading, and editing these files(something like an INI)?
Ummm did you look at the standard library before asking any on this?
If you are a total newbie I'll give you a start it is in the
Python/Lib folder.
Look for a module called ConfigParser.py ;)
I might post a code sample if I am up to it....so much turkey, and
cookies.
I want it to be powerful,
yet simple and minimalistic, not requiring a huge amount of overhead.

Don't we all!

M.E.Farmer

Jul 18 '05 #2
Aaron <fl********@gmail.com> writes:
Hi,

I'm interested in creating a large number of configuration files which I
have no experience doing in python. The fields will be static for the most
part. But design changes and I might want to add new fields in the future..

My question is - whats the best module for creating, reading, and editing
these files(something like an INI)? I want it to be powerful,
yet simple and minimalistic, not requiring a huge amount of overhead.

I've heard of xml, and have seen it used in both html fashion, and
likewise, without any tags at all- just spaces in between entries; why is
this? CSV is another thing I've seen thrown around on online
documentation. Whats the difference between the two, and which one should
I use(if either)?


M.E. Farmer already suggested the ConfigParser module, and I have to
concurr with him - it basically handles INI files.

XML is verbose. It allows the construction of complex data structures
(it's been called S-expressions with brokeits). It's primary advantage
is that there are tools for dealing with XML sanely - XML editors,
validators, parsers, and similar things. Without those tools, it can
be a PITA to deal with. So if your configuration is simple enough to
be captured by an INI file, avoid XML. If not, then googling for "xml
editor windows free" turns up a fair number of hits. For Unix, I used
to use an XML editor called Ted that was written in Python, but can't
turn anything up on google. There are xml editors for both KDE and
Gnome. Personally, I use psgml, which is an emacs package that handles
both xml and it's parent sgml.

CSV stands for Comma Separated Values. It's primarily an interchange
format for spreadsheet programs. While there is a default csv module
(that also handles tab separated values, and other arbitrary
separators), it's not the right tool for use as a config file.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 18 '05 #3
Here are two functions that show how to use ConfigParser.

py>def ConfigWrite(key, value, section, cfgpath):
.... import ConfigParser, pprint
.... parser=ConfigParser.ConfigParser()
.... cfg = open(cfgpath,'w')
.... parser.add_section(section)
.... Pretty = pprint.PrettyPrinter()#optional
.... value = Pretty.pformat(value)#optional
.... parser.set(section,key,value)
.... parser.write(cfg)
.... cfg.close()
py>def ConfigReader(key, section, cfgpath):
.... import ConfigParser
.... parser=ConfigParser.ConfigParser()
.... parser.read(cfgpath)
.... return parser.get(section,key)
Hope that helps...now *where* are those sugar cookies
M.E.Farmer

Jul 18 '05 #4
thanks for the replies, guys!

MEFarmer, that example helps remove a lot of the confusion, thanks!
I've looked through the SDL but there are so many different ways to do
it, I wasn't which one was hands down best

And Mike, I wish they would stick explanations like that in the SDL!
Would help make breaking into the language a lot easier for newbs like
me.

(Spending time on these newsgroups is giving me more questions that
answers heh )

Jul 18 '05 #5
>thanks for the replies, guys!

Your welcome, glad I could help.
(Spending time on these newsgroups is giving me more questions that
answers heh )

Thats good as long as it motivates you to learn ;)
M.E.Farmer

Jul 18 '05 #6

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

Similar topics

1
by: TT (Tom Tempelaere) | last post by:
Hey everyone, I'm currently writing software for a project that uses a lot of Xml files for configuration. The project is written in C#/.NET. Each such xml file has a schema defined for it (Xsd...
5
by: rdcpro | last post by:
In reading MSDN docs on creating custom Configuration sections, I found this page: ...
5
by: NoNickname | last post by:
Basically, how do I know that the release versions of all components are being published? The Build | Configuration Manager is confusing me a little in VS2005. I have three projects in my...
5
by: Ivan Weiss | last post by:
Hey all, I am trying to add a configuration file to my app so that I can store configuration options and provide a form to allow the user to change them. I know that these used to always be in...
6
by: yaron | last post by:
Hi all, I want to give a sample console application for the user with 2 configuration files. I want to give also a 2 .bat files for running the sample application, one for each configuration...
0
by: metaperl | last post by:
A Comparison of Python Class Objects and Init Files for Program Configuration ============================================================================= Terrence Brannon bauhaus@metaperl.com...
9
by: KarlM | last post by:
After reading some articles regarding confuguration data I'm a bit confused. Where is the right place for storing configuration data? - XML-files? - registry? - INI-files? (from a users point...
7
by: Peter Bradley | last post by:
OK. A bit behind the times, I know; but we're just moving over to .NET 2.0. How on earth do you manage configuration settings in a class library in .NET 2.0? In version 1.1, we used a handy class...
4
by: aSoundMind | last post by:
Hi there, I recieve this error Server Error in '/integrate' Application. -------------------------------------------------------------------------------- Configuration Error Description: An...
1
by: ajmerasunny | last post by:
Hi All, I have a java web application in which I need to read a configuration file(WebAgent.conf) that has the reference of another configuration file(SmHost.conf). I am placing both these...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.