configobj - use of

B

Bruce

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']['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?
 
S

Steve Holden

Bruce said:
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']['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['a']

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

print csec.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 ----------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top