|
From: Michael H. <ma...@ma...> - 2009-12-11 17:51:47
|
Am 11.12.2009 um 15:32 schrieb Michael Foord: ... >> The spec is: >> >> axis3_safe_margin = string(default= "%(ax3_letter)s safety margin >> [mm]:") >> >> The task is: >> - if the default ini file does not exist, generate it from the spec. >> - when reading the default .ini back in, I want the string equivalent >> as generated by: >> >> <foo>.axis3_safe_margin = "%(ax3_letter)s safety margin [mm]:" >> ---------------------------^^^^^^^^^^^^^ note - no mutilation here ... > Have you tried the interpolation attribute? Does that not work? Not for me. See attached example below which shows what I'm referring to. interpolation=False in the ConfigObj constructor, and I didnt find a way to express that extra for the validator. The problem seems to be the validate() function which insists on interpolating even if interpolation=False, and this should be fixed. Version was 4.6.0 . > http://www.voidspace.org.uk/python/configobj.html#interpolation > > Try setting it to False before validation and then back to True > after. It can also be passed as a keyword argument to the ConfigObj > constructor. > > Also you are incorrect that interpolation is only done against the > DEFAULT section. Version 4.4 contained a lot of improvements to the > interpolation engine and I believe this was one of the changes: Technically you are right - interpolation works against several sections - inner to outer. My point is: Insisting exclusively on intra-file interpolation between variables and formats - and copping out if a format cant be interpolated - is very limiting in the sense of what you can interpolate against (e.g. my program's variables, options, path etc ) once you want to actually use these variables. My suggestion is to provide a way to turn interpolation in the validator off completely, even in the validate() function. I would really appreciate a solution for this. thanks in advance Michael > > http://www.voidspace.org.uk/python/configobj.html#version-4-4-0 > http://www.voidspace.org.uk/python/configobj.html#string-interpolation > > """ > Interpolation checks first the current section to see if name is the > key to a value. ('name' is case sensitive). > > If it doesn't find it, next it checks the 'DEFAULT' sub-section of > the current section. > > If it still doesn't find it, it moves on to check the parent section > and the parent section's 'DEFAULT' subsection, and so on all the way > up to the main section. > """ > > > All the best, > > Michael Foord >> my suggestion: an interpolation=(True|False) parameter to validate() >> and please leave my strings untouched... >> >> >> thanks un advance >> >> Michael >> >> >> >> >> >> ------------------------------------------------------------------------------ >> Return on Information: >> Google Enterprise Search pays you back >> Get the facts. >> http://p.sf.net/sfu/google-dev2dev >> _______________________________________________ >> Configobj-develop mailing list >> Con...@li... >> https://lists.sourceforge.net/lists/listinfo/configobj-develop >> > > > -- > http://www.ironpythoninaction.com/ > http://www.voidspace.org.uk/blog > |