Title: Signature.html
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:
On Wed, Feb 18, 2009 at 1:01 PM, Wayne Watson <sierra_mtnv...@sbcglobal.net> wrote:
OK, I got the ObjectConfig and Validate downloads, and copied your Global class successfully. Don't I need to get the two files into Python as a module? How does that work?

Simplest: put them in the same folder as your own program.  More standard: put them in one of the folders in your Python path - same general idea as the DOS search path, it's a list of directories where Python will look for modules you ask it to import.

>From the docs: (http://docs.python.org/tutorial/modules.html)

The Module Search Path

When a module named spam is imported, the interpreter searches for a file named spam.py in the current directory, and then in the list of directories specified by the environment variable PYTHONPATH. This has the same syntax as the shell variable PATH, that is, a list of directory names. When PYTHONPATH is not set, or when the file is not found there, the search continues in an installation-dependent default path; on Unix, this is usually .:/usr/local/lib/python.

Actually, modules are searched in the list of directories given by the variable sys.path which is initialized from the directory containing the input script (or the current directory), PYTHONPATH and the installation- dependent default. This allows Python programs that know what they're doing to modify or replace the module search path. Note that because the directory containing the script being run is on the search path, it is important that the script not have the same name as a standard module, or Python will attempt to load the script as a module when that module is imported. This will generally be an error. See section Standard Modules for more information.



_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

--
           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/>



--
www.fsrtechnologies.com

_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

--
           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

Reply via email to