|
From: Stef M. <s.m...@ru...> - 2008-01-07 20:20:11
|
hello,
I'm using ConfigObj for writing/reading inifiles for a couple of months.
Until now I did a number of conversions myself,
but now I discovered a number of switches,
which in general do it much better than my own program (no wonder ;-)
These are my switches
list_values = True,
write_empty_values = True,
unrepr = True )
It looks really good, even for complex nested structures.
But I've a few problems with non-standard types, like wx.Colour,
which is basically a tupple with some constraints.
In writing, ConfigObj writes:
CS_SN1 = [wx.Colour(224, 224, 224, 255), True, True, True, False]
that seems great, but ...
... I get an error if ConfigObj tries to read it back.
So I made a workaround, which works ok:
def Write (self, name, value):
if type(value) in [bool,int,str,float,list,tuple] :
self[self.Section][name.strip()] = value
else :
try :
# try to convert to tupple,
# something like a wx.Colour can not be read back,
# but can just as well be written/read as a tupple
value = tuple ( value )
self[self.Section][name.strip()] = value
except :
self[self.Section][name.strip()] = str(value)
self.Modified = True
Why can't ConfigObj not read back wx.Colour (and others) ?
Any switches not set correct ?
And if it's not possible, is my workaround correct (btw doesn't work for
nested non-standard types) ?
thanks,
Stef Mientki
|