Using ConfigParse

  • Thread starter Zunbeltz Izaola
  • Start date
Z

Zunbeltz Izaola

Hi to all !

I've subclassed ConfigParse in the folowing way.

class DifracConfigParser(ConfigParser):
def __init__(self, defaults=None):
ConfigParser.__init__(self, defaults)
self.readfp(open('defaultdifrac.cfg'))

def save(self):
print "Enter save"
self.write(open('defaultdifrac.cfg','w'))
self.read(open('defaultdifrac.cfg'))
print "OUt save"


I use the values from the defaultdifrac.cfg file in my dialogs (using
wxpython) and change them via validators. After closing a dialog that
changes the values (after validating) i call de save method, but the
file is not changed.

Any Idea?

Thanks in advance

Zunbeltz


--
Zunbeltz Izaola Azkona | wmbizazz at lg dot ehu
dotes
Materia Kondentsatuaren Fisika Saila |
Zientzia eta Teknologia Fakultatea | Phone: 34946015326
Euskal Herriko Unibertsitatea |
PK 644 | Fax: 34 944648500
48080 Bilbo (SPAIN) |
 
P

Peter Otten

Zunbeltz said:
def save(self):
print "Enter save"
self.write(open('defaultdifrac.cfg','w'))
self.read(open('defaultdifrac.cfg'))
print "OUt save"

I would explicitly close the file before trying to read it.
.... f = file(fn, "w")
.... f.write(s)
.... if close: f.close()
.... return file(fn).read()
....''

Peter
 
Z

Zunbeltz Izaola

Peter Otten said:
I would explicitly close the file before trying to read it.

... f = file(fn, "w")
... f.write(s)
... if close: f.close()
... return file(fn).read()
...
''

Thanks for the sugestion but it doen't work, i don't know wy
CofigParser doesn't write the file

Zunbeltz

--
Zunbeltz Izaola Azkona | wmbizazz at lg dot ehu
dotes
Materia Kondentsatuaren Fisika Saila |
Zientzia eta Teknologia Fakultatea | Phone: 34946015326
Euskal Herriko Unibertsitatea |
PK 644 | Fax: 34 944648500
48080 Bilbo (SPAIN) |
 
P

Peter Otten

Zunbeltz said:
Thanks for the sugestion but it doen't work, i don't know wy
CofigParser doesn't write the file

I looked it up in the source: the read() method expects a filename or a
sequence of filenames. Incidentally that means, that every line in your
config-file is interpreted as a filename. It doesn't matter that none of
these files exist, as all IOErrors are silenced by the method.

self.readfp(open('defaultdifrac.cfg'))

or

self.read("defaultdifrac.cfg")

in your save() method instead of self.read(open('defaultdifrac.cfg')) should
fix the problem. That would of course mean that ConfigParser *does* write
the file, only doesn't read it back. Can you confirm that?

Peter
 
A

A. Lloyd Flanagan

Peter Otten said:
I looked it up in the source: the read() method expects a filename or a
sequence of filenames. Incidentally that means, that every line in your
config-file is interpreted as a filename. It doesn't matter that none of
these files exist, as all IOErrors are silenced by the method.

I too looked at the source. I understand why it ignores IOErrors
(though I'm not convinced it's a good idea), but I think I see a
problem with the ConfigParse module. I would think it should raise
some error if it can't find any file at all in the list you provide.
It seems to me that would be more useful than having an empty object.

Of course, it's probably not something we could change now...
 
Z

Zunbeltz Izaola

Thanks Peter and Lloyd. But the problem was on my code no on
ConfigParse. I was working in a module I think it was finished but the
problem was that after updating the values of the variables I did not
call the set funtion of the ConfigParse object.

Apologizes for bothering with silly questions :-(

Thanks again

Zunbeltz



--
Zunbeltz Izaola Azkona | wmbizazz at lg dot ehu
dotes
Materia Kondentsatuaren Fisika Saila |
Zientzia eta Teknologia Fakultatea | Phone: 34946015326
Euskal Herriko Unibertsitatea |
PK 644 | Fax: 34 944648500
48080 Bilbo (SPAIN) |
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top