Variable Substitution in commands or funtion names?

Chris Barker chrishbarker at home.net
Fri Jul 20 15:48:06 EDT 2001


fleet at teachout.org wrote:
> It looks like all I need to do to convert to your suggestion is add:
> 
> "Customers={" before "Antonia," replace the "=" after Antonia with an
> opening brace (and ditto for each of the other customers) and add a
> closing brace at the end of the customers.

Yep, that's all.

> >Customers = {smith: {"busname":"Smitties", "street":"123 West Ave"},
> >             jones: {"busname":"Joneses", "street":"123 East Ave"},
> >              ....}
> 
> And how are these NOT hardcoded into a module?  How would I access them
> otherwise?

Yes, they are also hardcode into the module if you type it in there. IN
fact, I have been know to do it myself, it's easier than putting it in a
text file, and then having to parse out the text file to build your
dict. The differences are: 

A) It's easier to access your data

B) You can now manipulate the data as well. It might start hardcoded,
but you can now manipulate the data far more easily after reading it in:
add to it, change it etc. 

C) you can also write it out more easily, in fact, if you use repr(),
you will get a string that can be eval() back to the same dict.

D) you can also change how the data is stored in the future, and still
access it in the same way, byt writing a class that emulates a mapping.
The data could be in text files, in a database, whatever.

> Thanks for the input.  I'll try this.
> 
>                                         - fleet -

have fun!

-Chris


-- 
Christopher Barker,
Ph.D.                                                           
ChrisHBarker at home.net                 ---           ---           ---
http://members.home.net/barkerlohmann ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------



More information about the Python-list mailing list