[Tutor] Looking for ConfigObj Documentation

Marc Tompkins marc.tompkins at gmail.com
Thu Feb 19 08:53:57 CET 2009


On Wed, Feb 18, 2009 at 7:42 PM, Wayne Watson
<sierra_mtnview at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090218/aa944cae/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Global_Config1.py
Type: text/x-python
Size: 975 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20090218/aa944cae/attachment-0001.py>


More information about the Tutor mailing list