On Wed, Feb 18, 2009 at 7:42 PM, Wayne Watson <sierra_mtnv...@sbcglobal.net>wrote:
> 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. > I hate to say it, but IDLE is really holding you back. It's convenient because it installs automagically with Python, but it does funky, confusing things - as in this case, where it's somehow stepped on the real error and assigned blame in the wrong place; you've already experienced its internal conflicts with Tkinter... I use wxPython for my GUI goodness, and swear by SPE (Stani's Python Editor). I don't want to re-ignite the IDE wars, but I definitely think you need to do yourself a favor and move away from IDLE. Anyway, I didn't mean for that to be a standalone program, but to be picked apart into chunks and dropped into an existing program (or, actually, just to be used as an example - maybe of what _not_ to do, but an example...) First error: if argv is None: argv = sys.argv <<== you haven't imported "sys" Second error: app = MyApp(0) <<== you haven't defined a class called "MyApp", so you can't do this... So I cut it down to just this bit: test = Global.cfgFile.validate(Global.vtor, copy=True) Global.cfgFile.write() (unindented all the way to the left, so that it executes as the main body of the program) and it works just fine... except: Third error (well, issue not error): Take all my comments out! They weren't meant to be included in final code. ConfigObj allows inline comments in your config file, and in the configspec - so my comments show up in there too. Here's what Initial.sen ends up looking like: mask_file_name = None gray_scale = True post_event_stack = False post_event_format = Tiff 2 show_real_time = False hourly_rate = 0 slowdown = 1 # I don't know what # this value is/does, so this is probably wrong start_time = 00:00:00 # or you could make the default None? stop_time = 00:00:00 # as a default latitude, if any... I've cut everything down; I'm attaching it as Global_Config1.py (just to avoid confusion with the earlier version). If you do actually want to use it as the basis of anything, you'll want to place the call to .validate() somewhere near the beginning of the action - remember, the call to .write() just afterward is completely optional; I had it in there for testing and have kept it in there for the same reason. > 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. > Ya know, I have no idea anymore. I thought I knew - but I just did a SET from a command prompt, and I don't have a PYTHONPATH variable. I seem to reacall something from a year or two ago... (looking now) Oh yes - there's a directory under your Python directory (Python25 in my case) called "Lib", and a folder under that called "site-packages"; any text files with the extension ".pth" will be scaned for the names of folders to add to the search path. As much as I love Python, I wish they'd get all this together... -- www.fsrtechnologies.com
import os, os.path from configobj import ConfigObj from validate import Validator import StringIO class Global(object): cfgFileName = os.getcwd() + os.sep + 'Initial.sen' 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) start_time = string(default="00:00:00") stop_time = string(default="00:00:00") lat = float(min=0.0, max=90.0) """ cfgSpec = StringIO.StringIO(tmpStr) cfgFile = ConfigObj(cfgFileName, configspec=cfgSpec, raise_errors=True, write_empty_values=True, create_empty=True, indent_type=' ', list_values=True) vtor = Validator() test = Global.cfgFile.validate(Global.vtor, copy=True) Global.cfgFile.write()
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor