Variable Substitution in commands or funtion names?

fleet at fleet at
Thu Jul 19 22:46:40 CEST 2001

>   Date: Thu, 19 Jul 2001 11:43:21 -0700
>   From: Chris Barker <chrishbarker at>
>fleet at wrote:
>> I think I may have gotten myself into a box.
>> I have a module "" that contains several dictionaries - each
>> references a different customer with address info, etc. such as:
>> smith={"busname":"Smitties", "street":"123 West Ave"}
>I think this is your problem right here. Having the customer name as a
>variable name is problematic, it means the customer's names are
>hard-coded into your module.

I've created dictionaries for each customer in  I don't have a
lot of customers and the information doesn't change often, therefore it's
pretty easy to edit the text file "" to make corrections or
add/delete customers.

If you'd like to do some charter fishing for rock fish in the Chesapeake,
here's what the actual first entry in my looks like:

   "name":"Nicholson & Daughters",
   "owner":"Capt. Charles Nicholson",
   "addr":"Bay Forest Rd.",
   "city":"Lexington Park",

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.

>You can do it, and some others have
>suggested how(you might also want to look at eval and exec),but why not
>use a nested dictionary?
>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

>now you do:
>from cust import Customers
>print Customers[CurCust]["street"]

Thanks for the input.  I'll try this.

					- fleet -

>Christopher Barker,
>ChrisHBarker at                 ---           ---           ---
> ---@@       -----@@       -----@@
>                                   ------@@@     ------@@@     ------@@@
>Oil Spill Modeling                ------   @    ------   @   ------   @
>Water Resources Engineering       -------      ---------     --------
>Coastal and Fluvial Hydrodynamics --------------------------------------

More information about the Python-list mailing list