Variable Substitution in commands or funtion names?

fleet at teachout.org fleet at teachout.org
Thu Jul 19 12:21:41 EDT 2001


You missed something.

>>>CurCust='smith' #assigned previously in program
>>>from cust import CurCust
Traceback (innermost last):
  File "<stdin>", line 1, in ?
  ImportError: cannot import name CurCust


and if I do:
>>>from cust import smith
>>>CurCust[2]
i

Not what I wanted.

The question is - how do I get:

"from cust import CurCust" to equal "from cust import smith"
and
"CurCust[2]" to equal "smith[2]"

In the program, CurCust can be assigned to smith, johnson, jones or even
Hao-Nghi :)

Regards,
					- fleet -

> Hi fleet,
>
> Just learn that when you write : from cust import CurCust
> ==> CurCust becomes local and you have to reference to it by :
> print CurCust["street"]
>
> regards,
> Hao-Nghi Au
> -----Original Message-----
> From: fleet at teachout.org [mailto:fleet at teachout.org]
> Sent: Thursday, July 19, 2001 2:26 PM
> To: python list
> Subject: Variable Substitution in commands or funtion names?
>
>
>
> I think I may have gotten myself into a box.
>
> I have a module "cust.py" that contains several dictionaries - each
> references a different customer with address info, etc. such as:
>
> smith={"busname":"Smitties", "street":"123 West Ave"}
>
> Parsing the csv output of a spreadsheet allows me to assign "smith" to a
> variable - CurCust.
>
> Now I want to do something like:
>
> from cust import CurCust
>
> print cust.CurCust["street"]
>
> Spent the evening trying to solve this (Learning Python, and Sam's Teach
> Yourself Python) then tried the archives.  The little I found on "variable
> substitution" almost seems to say "no way!" ???
>
> (I know someone is going to suggest a database.  That's a little further
> up the learning curve.  I can see it from here; but I'm not there yet.)
>
> Thanks for any assistance,
> 					- fleet -
>
>
>
>





More information about the Python-list mailing list