Title: Signature.html
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 2009

These 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., and change the values as the user enters new values by executing self.long =  124.33, when the user enters 124.33 via the GUI interface. The idea of the dictionary is to keep some basic structure for manipulation and organization of the variables without typing them in all the time as the code develops. As another example, when reading the config file, I only need to turn (transform, execute) each line into effectively something like self.long = 120.00. dcon would essentially a global.

There would be no explicit embedded code for this within the program. That is, nowhere would one see the line self.long = 150.22.


Kent Johnson wrote:
On Sat, Feb 7, 2009 at 3:20 PM, Wayne Watson
<sierra_mtnv...@sbcglobal.net> wrote:
  
Is it possible to do some thing like this with exec:

dcon0 = {'long':120.00, 'lat': 39.00, 'year': 2009}

Can I use exec or eval simply on this to get:
long = 120.00
lat   = 39.00
year = 2009

That is, initialize each of these three variables.
    

Yes, without exec:
long = dcon0['long']
etc.

but why? If you know the keys, you can hard-code the assignments as
above. If you don't know the keys, you are probably better off leaving
the values in the dict.

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

Reply via email to