473,407 Members | 2,359 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,407 software developers and data experts.

configobj - use of

I assume that you know the module configobj. I use it like this:
I have a config_file :

[sec1]
[[subsec1]]
a = 1
b = 2
[[subsec2]]
a = 3
b = 1

... ans so on

Then in the code I have c = configobj.ConfigObj(path_to_config file)

then I go like for instance

for s in c['sec1']:
print c['sec1'][s]['a']

Just think its awkward that its neccessary to use the c['sec1'] again
inside the loop,
guess I`d like it to be like
print s.a

instead

Is this the right way to use configobj?

May 24 '07 #1
1 1423
Bruce wrote:
I assume that you know the module configobj. I use it like this:
I have a config_file :

[sec1]
[[subsec1]]
a = 1
b = 2
[[subsec2]]
a = 3
b = 1

.. ans so on

Then in the code I have c = configobj.ConfigObj(path_to_config file)

then I go like for instance

for s in c['sec1']:
print c['sec1'][s]['a']

Just think its awkward that its neccessary to use the c['sec1'] again
inside the loop,
guess I`d like it to be like
print s.a

instead

Is this the right way to use configobj?
So bind a variable to the section, and write

csec = c['sec1']
for s in csec:
print csec[s]['a']

I don't think configobj support attribute-based access to the section
values, in which case

print csec[s].a

won't work.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
------------------ Asciimercial ---------------------
Get on the web: Blog, lens and tag your way to fame!!
holdenweb.blogspot.com squidoo.com/pythonology
tagged items: del.icio.us/steve.holden/python
All these services currently offer free registration!
-------------- Thank You for Reading ----------------

May 24 '07 #2

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

Similar topics

0
by: Fuzzyman | last post by:
A few functions I'm 'making available' (FWIW) and also a new project I'm starting.... http://www.voidspace.org.uk/atlantibots/pythonutils.html Slight updates to ConfigObj and StandOut (simple...
4
by: Fuzzyman | last post by:
There have been a couple of config file 'systems' announced recently, that focus on building more powerful and complex configuration files. ConfigObj is a module to enable you to much more *simply*...
5
by: Tom Willis | last post by:
How are the expert pythoneers dealing with config files? Is there anything similair to .net's config files or java's .properties? A quick search on google didn't return anything that looked...
0
by: Fuzzyman | last post by:
The response to pythonutils__ was very good. Especially the odict__ module (ordered dictionary) - it's had over one hundred and fifty downloads already. Thanks to some useful user feedback, Nicola...
10
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...
0
by: Fuzzyman | last post by:
Hello All, I've added (optional) unicode support for ConfigObj. This is now available from SVN. You can specify an encoding to decode the config file on reading. This maps to an encoding...
3
by: mwt | last post by:
I want to set default values for a ConfigParser. So far, its job is very small, so there is only one section heading, . Reading the docs, I see that in order to set default values in a...
3
by: noagbodjivictor | last post by:
Hi, I need a specific example. I have seen the docs, but I don't all the stuffs there. So basically, I need my config file to be created and read by my script. Here is a snippet # read...
1
by: Roopesh | last post by:
Hi, I am using ConfigObj to write email addresses, as a list. I am using email module functions to extract email addresses: to_address = header.get_all('To', ) address_list =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
0
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...
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.