That's something for me to ponder, setattr. I'd rather not go off and
pick up on something like ConfigParser at this stage. I'd like to keep
this code somewhat simple and easy to understand, but yet have some
flexibility for changes. Kent Johnson wrote: On Sat, Feb 7, 2009 at 4:21 PM, Wayne Watson <sierra_mtnv...@sbcglobal.net> wrote:Here's more detail. What I was hoping for was something like:exec "=" dcon This is fictitious of course, but would mean assign the values in [1] to [0]. Yes, it would be easy to loop and assemble elements into a string that would be executed by exec (or eval), or use some assignment line like your example. I have 30 or more of such assignments, and I would prefer not to have to write them as assignments. The end purpose here is to produce a config file, assign initial values, and change values. For example, the (text) file might look initially like: long 120.00 lat 39.00 year 2009Do you know about the ConfigParser module? http://docs.python.org/library/configparser.htmlThese would be written to the file by looping through dcon. Another time, I might want to initialize these variables within the program, in the form self.long = 120.00, etc.,Ok, that is different than long = 120.00 because the variable is an attribute of self. Try this, it will take all the items in dcon and set them as attributes of self: for key, value in dcon: setattr(self, key, value) Kent --
Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) Q: What do you do when your resistors get to hot? A: Open the switch and coulomb they off. -- Anon. (fortunately!) Web Page: <www.speckledwithstars.net/> |
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor