Yes, on F3 (ctrl-F). I use it a lot.  After the dust clears on how to correct this implementation, I'll give ConfigObj more consideration.  (I think a subsequent post I made with two images in it showing the layout of the program in action got side tracked here. I got a msg from the list, saying the moderator had to approve something--probably it.  Whatever I said in it might be somewhat irrelevant here. So I continue. See whoops at end!)

Ok, let's see how this works. I've defined this function and the config_var_list. stop time is the last entry shown. It is part of the constructor for mainloop, Sentinel_GUI. and loads sdict as shown.
        def Set_ConfigDictionary():

            config_var_list = (['config_file_name',  ['Initial.sen', STR]],                   
                ['mask_file_name',  ['xyz', STR]],
                    ...
                ['stop_time',  ['datetime.time(6, 0, 0)', DAT]],
                        ...
                )
            # load sdict
            sdict = {}
            for j in range(0, len(config_var_list)):
            #    print "j: ", j, "str part: ", str(config_var_list[j][0]), config_var_list[j][1]
                sdict[str(config_var_list[j][0])] = config_var_list[j][1][0]
                      ...
            self.sdict = sdict
            self.config_var_list = config_var_list
                      ...
sdict and config_var_list become global to Sentinel_GUI. The first index of conf_var_list maintains order for sdict. That is, when I want to output the config file, I use to to fetch from sdict what I need, which is a value and the "user" type, i.e., STR, DAT, BOO, etc.

Now in SaveConfigFile, I go merrily along thusly:

                   ...
        #                         SAVE CONFIG FILE
        items = self.sdict.keys()
        items.sort()
        for (j, conf_entry) in enumerate(self.config_var_list):
            varName = conf_entry[0]
            varType = self.config_var_list[j][1][1]
            # Note, date-time vars are in hh:mm:ss
            varValue = eval('self.' + varName)
            var_assignment = varName + "=" + str(varValue)    <<--- Beep, beep
            config_file.write(var_assignment + "\n")
                         ...

"Beep, beep" shows the likely problem.  I had coded this loop earlier to try (and not succeeding) to take into consideration DAT, BOO, ..., etc, but put aside how to handle the var_assignment statement (Note, Strictly speaking I should be using TIM and not DAT, for clarity.).   Here, I suspect that I should put out something like datetime.time(11, 20, 10). The time being 11:00:10. Instead I chose, to put 11:00:10 in the file. I'm still a bit confused about what the file entry should be here. However!

I think I may have drifted into the realm of :          :-)  
    UCFformLength = integer(min=50, max=80, default=66)
    FIformLength = integer(min=50, max=80, default=64)
Maybe things are looking up for ConfigObj!!!

Whoops footnote: I think I got you and Kent confused, but I think I'm on track here with thinking of the right person. I posted the two pix to him.

Marc Tompkins wrote:
On Tue, Feb 17, 2009 at 11:01 AM, Wayne Watson <sierra_mtnv...@sbcglobal.net> wrote:
Here's the print from the code line below.

Second line from the top.

There it is - stop_time is a str at this point in the program, so has no strftime attribute or method.  Step back through your code and see why...  I find Control-F very helpful in situations like this!
 

Regarding, ConfigObj, I was aware of it when I decided to go this route. That's the one that uses has an init file like Windows?  Rather than have to go through a learning process on it (the Win init module/object), and some uncertainty about it's acceptability in my situation, I thought I'd be more exploratory and proceed as I have. So far it has paid off in many learning dividends. ConfigObj, if not the Win stuff, may be attractive. Anyway, I'd like to proceed for the moment with this effort.

There's nothing sacred about the ".ini" extension - any text file that contains "variable = value" pairs is game.  ConfigObj is not Windows-centric.  The advantage - which is what I was trying to show when I posted that gosh-awful hunk of code - is that you can define the format of the file in one central section of your program - it could even be a separate module if you wanted - and in one swell foop you tell ConfigObj the name of the variable, its type, acceptable values or range, and a default value in case it's missing.  Opening, reading, closing, writing, validating - all handled. 

I certainly wouldn't want to dissuade you from writing your own as a learning exercise - I'm glad I did - but each time I need to update one of my old programs that still uses my homegrown ConfigFile, that's the first thing I re-factor.

--
www.fsrtechnologies.com

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

--

Signature.html
           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/>
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to