I took your "starter" code, and formatted it to be what I hope is an
acceptable program, Gobal_Config.py. See attached. I'm using Python
2.5.2. I put the two modules in the same folder with it, and executed
it in IDLE. I got this: ... File "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\configobj.py", line 1637, in _parse ParseError, infile, cur_index) File "C:\Sandia_Meteors\New_Sentinel_Development\Sentuser_Utilities_Related\sentuser\configobj.py", line 1748, in _handle_error raise error ParseError: Invalid line at line "1". As far as I can tell, line 1 of config.obj looks OK. It's a comment. Something is amiss. Does PYTHONPATH apply in Win XP? I haven't played at the level of paths for a long time in any OS. We can worry about an install "package" later for the modules. It might be best for the users of this program. When I was using Python 2.4, I could find an entry on Start for it, and get an item on it under Python 2.4 called something like Library Paths. I don't see that at all on Python 2.5. Bad memory, I just checked on my laptop, which has 2.4; however, I recall being able to probe Python library paths. This may be irrelevant. The ConfigObj 4 Introduction and Ref doc doesn't seem to associate it with any version of Python. Its version is 4.5.3. Puzzled ... Marc Tompkins wrote:
--
Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) "Nature, to be commanded, must be obeyed." -- Sir Francis Bacon Web Page: <www.speckledwithstars.net/> |
import os, os.path from configobj import ConfigObj from validate import Validator import StringIO class Global(object): cfgFileName = os.getcwd() + os.sep + 'Initial.sen' # current directory + "\" + filename -- # but you could put it anywhere and call it anything # create your spec as a multi-line string between triple quotes tmpStr = """ mask_file_name = string(default=None) gray_scale = boolean(default=True) post_event_stack = boolean(default=False) post_event_format = string(default="Tiff 2") show_real_time = boolean(default=False) hourly_rate = integer(min=0, default=0) slowdown= integer(min=0, max=10, default=1) # I don't know what # this value is/does, so this is probably wrong start_time = string(default="00:00:00") # or you could make the default None? stop_time = string(default="00:00:00") lat = float(min=0.0, max=90.0) # I have no idea what you'd want # as a default latitude, if any... """ cfgSpec = StringIO.StringIO(tmpStr) # turns the above string into a # file-like object, which ConfigObj is expecting cfgFile = ConfigObj(cfgFileName, configspec=cfgSpec, raise_errors=True, write_empty_values=True, create_empty=True, indent_type=' ', list_values=True) # creates # the actual ConfigObj object vtor = Validator() # creates a validator to match your config data against your spec #* Invoke the above code when your program starts - I do it just before my mainloop, like so: def main(argv=None): if argv is None: argv = sys.argv test = Global.cfgFile.validate(Global.vtor, copy=True) # tries to load cfgFile; # if it doesn't exist, creates it; fills in defaults for any missing values Global.cfgFile.write() # saves the validated file (you don't need to do this # here at the start, but I usually do) app = MyApp(0) app.MainLoop() if __name__ == '__main__': main() #* Your ConfigObj is ready to use! Simply access the contents like a regular # dictionary. To save back to the file, call the write() method. #Global.cfgFile['mask_file_name'] = 'bogus.txt' #Global.cfgFile.write() # maskFile = Global.cfgFile['mask_file_name'] # * Or use the values directly without copying to intermediate variables: # with open(Global.cfgFile['mask_file_name'], 'w+b') as maskFile: # maskFile.write('some bogus text')
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor