By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,814 Members | 1,111 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,814 IT Pros & Developers. It's quick & easy.

configobj - use of

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.