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

Using ConfigParse


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) |
Jul 18 '05 #1
5 1656
Zunbeltz Izaola wrote:
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.
def save(fn="tmp.txt", s="so what", close=True): .... f = file(fn, "w")
.... f.write(s)
.... if close: f.close()
.... return file(fn).read()
.... save() 'so what' save(s="another") 'another' save(s="yet another", close=False)

''

Peter

Jul 18 '05 #2
Peter Otten <__*******@web.de> writes:
Zunbeltz Izaola wrote:
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.
def save(fn="tmp.txt", s="so what", close=True): ... f = file(fn, "w")
... f.write(s)
... if close: f.close()
... return file(fn).read()
... save() 'so what' save(s="another") 'another' save(s="yet another", close=False)

''


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

Zunbeltz

Peter


--
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) |
Jul 18 '05 #3
Zunbeltz Izaola wrote:
Peter Otten <__*******@web.de> writes:
Zunbeltz Izaola wrote:
> 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.
>>> def save(fn="tmp.txt", s="so what", close=True):

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

'so what'
>>> save(s="another")

'another'
>>> save(s="yet another", close=False)

''


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

Jul 18 '05 #4
Peter Otten <__*******@web.de> wrote in message news:<ca*************@news.t-online.com>...
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...
Jul 18 '05 #5

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) |
Jul 18 '05 #6

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

Similar topics

2
by: rawCoder | last post by:
Hi All, I have a *.cer file, a public key of some one and I want to encrypt some thing using this public key. Can someone point me to a sample code for Encrypting some file using...
1
by: Mike | last post by:
When trying to compile (using Visual Web Developer 2005 Express Beta; frameworkv2.0.50215 ) the source code below I get errors (listed below due to the use of ICallBackEventHandler. Ultimately I...
10
by: Christopher Benson-Manica | last post by:
Why can't I use a class destructor in a using declaration: using MyClass::~MyClass; ? -- Christopher Benson-Manica | I *should* know what I'm talking about - if I ataru(at)cyberspace.org ...
17
by: beliavsky | last post by:
Many of my C++ programs have the line using namespace std; but the "Accelerated C++" book of Koenig and Moo has many examples where the library names are included one at a time, for example ...
8
by: Petter Reinholdtsen | last post by:
I ran into a problem on HP-UX 11.00 the other day, where it refused to compile a program using 'using namespace std;' at the top. The reason seem to be that the compiler refuses to accept 'using...
14
by: john.burton.email | last post by:
I've done some extensive searching and can't seem to find an answer to this - Is it correct to using "using" with templates, for example: using std::vector; Or do I need to specify the type...
5
by: Enos Meroka | last post by:
Hallo, I am a student doing my project in the university.. I have been trying to compile the program using HP -UX aCC compiler, however I keep on getting the following errors. ...
3
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0...
1
by: Neal Becker | last post by:
I have all my options setup with optparse. Now, I'd like to be able to parse an ini file to set defaults (that could be overridden by command line switches). I'd like to make minimal change to...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.